My code is below, I'm thinking it has something to do with my if / else statement. Essentially I want to make sure there is at least one radio button in a group checked before I open the next page. Once this works, I'll set it up so that if one of the radiobuttons in the group isn't checked then It will display an error message.
public void onClickListenerButton() {
radioGroup_gender = (RadioGroup) findViewById(R.id.radioGroup_gender);
radioGroup_course = (RadioGroup) findViewById(R.id.radioGroup_course);
button_splits = (Button)findViewById(R.id.button_splits);
button_splits.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.idealsplit.admin.idealsplit.ResultsActivity");
int selectedID_gender = radioGroup_gender.getCheckedRadioButtonId();
int selectedID_course = radioGroup_course.getCheckedRadioButtonId();
radioButton_gender = (RadioButton) findViewById(selectedID_gender);
radioButton_course = (RadioButton) findViewById(selectedID_course);
CharSequence gender, courseType, age, event, time;
if (selectedID_gender == -1) {
//Throw Error
isNull = true;
} else if (selectedID_course == -1) {
//Throw Error
isNull = true;
} else {
courseType = radioButton_course.getText();
gender = radioButton_gender.getText();
startActivity(intent);
}
}
}
);
}
And here is the logcat:
03-01 08:52:22.060 19234-19234/com.idealsplit.admin.idealsplit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.idealsplit.admin.idealsplit, PID: 19234
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.idealsplit.admin.idealsplit/com.idealsplit.admin.idealsplit.ResultsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.idealsplit.admin.idealsplit.ResultsActivity.onCreate(ResultsActivity.java:96)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Thanks for any and all help with this, if more information was needed let me know!
**If it helps I was following this youtube tutorial: https://www.youtube.com/watch?v=3f0NAn5xFy4