I'm getting this null exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.TextView.getText()' on a null object reference
and I don't know why.
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);
}
});
}
my 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" />
any ideas?
TextView
idInfo
is exist in youractivity_report.xml
Try declaring
idInfo
as global.UPDATE:
To get selected
radioButton
text:Hope this will help~