I have two radio button in my app Yes and No.So whenever user select Yes then I want to show bottom sheet dialog but app is crashing whenever it launches.
It is showing error below:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.TextView.getText()' on a null object reference
Below is my code:
public class Signup extends AppCompatActivity {
RadioButton radioButton;
RadioGroup radioGroup;
BottomSheetDialog bottomSheetDialog;
int selectedID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
radioGroup = findViewById(R.id.radioGroup);
selectedID = radioGroup.getCheckedRadioButtonId();
radioButton = findViewById(selectedID);
if(radioButton.getText().toString().equals("Yes")){
bottomSheetDialog = new BottomSheetDialog(Signup.this);
bottomSheetDialog.setContentView(R.layout.bottom_file_type);
bottomSheetDialog.setCanceledOnTouchOutside(true);
bottomSheetDialog.show();
}
}
}