these calls in onPostResume
of the abstract activity are definitely happening after setContentView(R.layout.activity_method_two);
in the child classes. But I get java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioButton.setChecked(boolean)' on a null object reference
anyway
Why can't I do this?
public class MethodTwo extends AbstractMethod {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_method_two);
}
@Override
void set_default_method() {
rb_default = (RadioButton) findViewById(R.id.radio_button_method_two);
}
}
and
public abstract class AbstractMethod extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
RadioGroup rg_method;
RadioButton rb_default;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
set_default_method();
}
@Override
protected void onPostResume() {
super.onPostResume();
rb_default.setChecked(true);
rg_method = (RadioGroup) findViewById(R.id.radio_group_method_select);
rg_method.setOnCheckedChangeListener(this);
}
produces an error in the stack trace:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioButton.setChecked(boolean)' on a null object reference
if I move the setContentView
into the onCreate in the abstract class (just after super.oncreate()
), it works .. but then I dont have an abstract class for multiple child classes.