What does this stacktrace indicate?

12-15 19:33:44.836 30217-30217/inc.developersn.laway E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: inc.developersn.laway, PID: 30217
                                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Switch.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference
                                                                               at inc.developersn.laway.Fragment.HomeFragment.onCreate(HomeFragment.java:67)
                                                                               at android.support.v4.app.Fragment.performCreate(Fragment.java:2172)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1243)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
                                                                               at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
                                                                               at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
                                                                               at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1998)
                                                                               at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:709)
                                                                               at android.os.Handler.handleCallback(Handler.java:815)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                               at android.os.Looper.loop(Looper.java:207)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5728)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

I have a quite simple app (that has 6 Activities, 4 Fragments, 2 services and 1 BroadcastReceiver), that has no external dependencies - I only use the glide library and the Android Support Library. Today, I was trying to initialize a switch in a fragment - this resulted in an unexpected error. I found the issue and addressed it. But now I get this random error, and my app won’t launch as soon as I try to launch it, I get this error. Any clue what this indicates? I have tried a clean build, rebuild, make, but nothing has sorted the problem out till now. It would be great if anyone tells me where I’m going wrong.

It’s a NullPointerException. You’re trying to invoke a method on a null object reference somewhere. Check the value of your switch.

1 Like

It’s fixed now. I forgot to initialize the switch