I added this Radio Group, with it's radioButtons, although now I'm getting that my whole Radio Group is null? A very interesting thing is, my app doesn't detect this error when i run it on a device with an API of 22, but when I RERUN it on the 28API emulator this error does appear. Here is the code:
radioGroup = findViewById(R.id.radioGroup2);
Rd1= findViewById(R.id.radioButton5);
Rd2= findViewById(R.id.radioButton6);
radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (Rd1.isChecked()) {
attemptLogin();
Intent intent = new Intent(LoginActivity.this, BottomActivity.class);
startActivity(intent);
}else {
if(Rd2.isChecked()) {
attemptLogin();
Intent intent = new Intent(LoginActivity.this, LoginActivity2.class);
startActivity(intent);
}
}
}
} );
Here is the XML code, I have tried adding the RadioGroup view, to my Login Activity, in order to place both buttons above each other, although once i did that i immediatly got this error.
<RadioGroup
android:id="@+id/radioGroup2"
android:layout_width="361dp"
android:layout_height="125dp"
android:layout_gravity="bottom"
android:background="@color/licolor"
android:gravity="center"
android:layout_marginTop="20dp"
android:orientation="vertical"
tools:ignore="UselessParent">
<RadioButton
android:id="@+id/radioButton5"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="16dp"
android:background="@drawable/mybutton"
android:gravity="center"
android:text="@string/register"
android:textColor="#fafafa"
android:textStyle="bold"
android:textSize="19sp"
android:button="@null"/>
<RadioButton
android:id="@+id/radioButton6"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="16dp"
android:background="@drawable/mybutton"
android:gravity="center"
android:text="@string/login"
android:textColor="#fafafa"
android:textStyle="bold"
android:textSize="19sp"
android:button="@null"/>
</RadioGroup>
And there you have the following error:
Attempt to invoke virtual method 'void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)' on a null object reference