I have a tabbed activity with 2 fragments. I want use the Views in those fragments.
OnCreate(Tabbed host activity)
switchButton1 = (Switch) findViewById(R.id.switch1);
switchButton1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean bChecked) {
if (bChecked) {}
When I run the app I get an error that it could not find the view. This is the error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Switch.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object referencehere