I making a fitness application in Android Studio and my projcet has Multiple Activities (6). I am trying to get the value of the radiogroup from the ThirdActivity in the SixthActivity. However, when I try to do this, I get the error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.RadioGroup.getCheckedRadioButtonId()' on a null object reference
I have made sure that all the names for the variables in the xml code are correct and am still running into the same problem.
SixthActivity.java
Intent intent=getIntent();
String experience =intent.getStringExtra("Experience");
I would like to be able to get the value from thirdRadioGroup RadioGroup in ThirdActivity while being in the SixthActivity.
new code:
//ThirdActivity.class
thirdRadioGroup = findViewById(R.id.thirdRadioGroup);
int radioIdExperience = thirdRadioGroup.getCheckedRadioButtonId();
experience = (RadioButton) findViewById(radioIdExperience);
Intent intent = new Intent(this, SixthActivity.class);
intent.putExtra("Experience", experience.getText());
startActivity(intent);
Now, again this throw NullPointerException
..
error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.RadioButton.getText()' on a null object reference