So, I am going through the Tutorial #12 and everything is working fine. I then try to go onto Tutorial #13 for Saving/Restoring Last-Read Position and the app crashes:
04-10 15:59:26.510: E/Trace(704): error opening trace file: No such file or directory (2)
04-10 15:59:27.491: D/AndroidRuntime(704): Shutting down VM
04-10 15:59:27.491: W/dalvikvm(704): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
04-10 15:59:27.500: E/AndroidRuntime(704): FATAL EXCEPTION: main
04-10 15:59:27.500: E/AndroidRuntime(704): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.commonsware.empublite/com.commonsware.empublite.EmPubLiteActivity}: java.lang.NullPointerException
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.os.Looper.loop(Looper.java:137)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-10 15:59:27.500: E/AndroidRuntime(704): at java.lang.reflect.Method.invokeNative(Native Method)
04-10 15:59:27.500: E/AndroidRuntime(704): at java.lang.reflect.Method.invoke(Method.java:511)
04-10 15:59:27.500: E/AndroidRuntime(704): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-10 15:59:27.500: E/AndroidRuntime(704): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-10 15:59:27.500: E/AndroidRuntime(704): at dalvik.system.NativeStart.main(Native Method)
04-10 15:59:27.500: E/AndroidRuntime(704): Caused by: java.lang.NullPointerException
04-10 15:59:27.500: E/AndroidRuntime(704): at com.commonsware.empublite.ModelFragment.executeAsyncTask(ModelFragment.java:51)
04-10 15:59:27.500: E/AndroidRuntime(704): at com.commonsware.empublite.ModelFragment.deliverModel(ModelFragment.java:38)
04-10 15:59:27.500: E/AndroidRuntime(704): at com.commonsware.empublite.ModelFragment.onActivityCreated(ModelFragment.java:29)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:891)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.Activity.performStart(Activity.java:5018)
04-10 15:59:27.500: E/AndroidRuntime(704): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
04-10 15:59:27.500: E/AndroidRuntime(704): ... 11 more
I tried to comment out the code I did until the last point that it was working, but that didn't seem to work. I am not really sure how to read this stack trace either. What should I be looking at to fix this problem?
Thanks.
I am not really sure how to read this stack trace either. What should I be looking at to fix this problem?
Line 51 of ModelFragment.java, in the executeAsyncTask()
method is where you are crashing (see last stack trace stanza, starting with Caused by: java.lang.NullPointerException
).
Your line numbers and those in the answers are not completely lining up. However, the only way executeAsyncTask()
could have a NullPointerException
is if the AsyncTask
you are passing in is null
, and that should not be possible as you define those tasks immediately before calling executeAsyncTask()
in the deliverModel()
method. Perhaps you missed a line in deliverModel()
.