0

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
Bozhidar
  • 29
  • 4
  • You should include a class and method in your code snippet. Also post the entire error message and indicate which line causes it. – Code-Apprentice Jan 22 '17 at 14:01
  • Please post the full stack trace and show us which line causes the error. You should also show the `class` and method which contains the code posted here. – Code-Apprentice Jan 23 '17 at 04:11
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Code-Apprentice Jan 23 '17 at 04:12

0 Answers0