I haven't encountered a stack trace such as this. It's particularly weird because I can only get the error to be thrown when debugging. (Running the app without debugging does not yield this error). This happens upon selecting a particular page from my navigation drawer. I have just recently switched from activities to fragments and I may not have handled my fragment transactions correctly. I would appreciate any input! Thanks a lot guys, happy holidays!
Here's the stack trace:
Process: com.kohlerbear.whowascnscalc, PID: 2415
java.lang.NullPointerException: Attempt to read from field 'boolean android.support.v4.app.BackStackRecord.mAddToBackStack' on a null object reference
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:685)
at android.support.v4.app.FragmentManagerImpl.execPeerrorndingActions(FragmentManager.java:1479)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
at android.os.Handler.handleCallback(Handler.java:740)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5223)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
And here is how I am handling my fragment change (Not sure if this is the problem, just judging by the fact that the trace mentions the backstack). The app crashes (again, only when debugging) regardless of whether or not I call ft.addToBackStack(null)
.
Fragment frag = new ThirdScreenFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, frag);
ft.addToBackStack(null);
ft.commit();`
Any ideas and input are appreciated :)