のjava.lang.NullPointerException:起動しようとします仮想メソッド 'java.lang.CharSequence android.widget.TextView.getText()' nullオブジェクトの参照
と私はなぜわかりません。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.LoginRegister);
setContentView(R.layout.activity_report);
final TextView infoid = (TextView) findViewById(R.id.idInfo);
RadioGroup rg = (RadioGroup)findViewById(R.id.rg);
final String radiovalue = ((RadioButton)findViewById(rg.getCheckedRadioButtonId())).getText().toString();
...
Button sendButton = (Button) findViewById(R.id.button2);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = infoid.getText().toString(); //what is wrong?
Log.w("message: ", radiovalue);
}
});
}
私のxml
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/idInfo"
android:hint="Add some extra information"
android:layout_weight="0.09"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp" />
<Button
android:text="Report"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2" />
任意のアイデア?
あなたの迅速な答えを与えるだろうデバッガを使用するのに役立ちます
希望 –
なぜあなたは法を開始した後でテキストを取得しようとしていますか?とにかく、ivity? –
@ cricket_007私はこのアクティビティに取り組んでいます。この目的をレポート関数onResponseに変更します... –