java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.report/com.example.report.started_report}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.CheckBox.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference

  1. 0

    Android - A Checkbox when isChecked, shows button

    Stack Overflow | 3 months ago | HextechEnthusiast
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.report/com.example.report.started_report}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.CheckBox.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference
  2. 0

    Android Checkbox getchecked (CompoundButton.OnCheckedChangeListener (without button click event))

    Stack Overflow | 2 years ago | Omar BISTAMI
    java.lang.RuntimeException: Unable to start activity ComponentInfo{sqllistviewdemo.wptrafficanalyzer.in.radiobutton/sqllistviewdemo.wptrafficanalyzer.in.radiobutton.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.CheckBox.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference
  3. 0

    NullPointerException: 'void android.widget.Switch.setOnCheckedChangeListener

    Stack Overflow | 1 year ago | Georgi Koemdzhiev
    java.lang.RuntimeException: Unable to start activity ComponentInfo{koemdzhiev.com.quickshoppinglist/koemdzhiev.com.quickshoppinglist.ui.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Switch.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    added Switch widget in toolbar, it is null when referring to it

    Stack Overflow | 1 year ago | Georgi Koemdzhiev
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Switch.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference
  6. 0

    added Switch widget in toolbar, it is null when referring to it

    Stack Overflow | 1 year ago | Georgi Koemdzhiev
    menu.xml: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> <item android:id="@+id/action_how_to_use" android:title="@string/action_how_to_use" android:orderInCategory="500" app:showAsAction="never"/> <item android:id="@+id/action_rearrange" android:title="Rearrange" app:showAsAction="ifRoom" app:actionLayout="@layout/switch_layout"/> </menu> Code in main activity: public class MainActivity extends AppCompatActivity { ... private Switch mySwitch; ... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mySwitch = (Switch)findViewById(R.id.switch1); mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { } }); } Trace: .NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SwitchCompat.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke virtual method 'void android.widget.CheckBox.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference

      at com.example.relatoriodeobras.started_alvara.onCreate()
    2. com.example.relatoriodeobras
      started_alvara.onCreate
      1. com.example.relatoriodeobras.started_alvara.onCreate(started_alvara.java:21)
      1 frame
    3. Android Platform
      ActivityThread.performLaunchActivity
      1. android.app.Activity.performCreate(Activity.java:5990)
      2. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
      3. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
      3 frames