EmPubLite教程12崩溃

时间:2013-10-01 16:14:43

标签: android commonsware

我一直在阅读Busy Coders Guide 5.1版的教程12。

当我运行模拟器时,应用程序在启动期间不断崩溃。我不清楚我的logcat文件中要查找什么。能帮我理解我需要找的东西吗?谢谢。

我搜索过,没有看到有关教程12的任何其他帖子。如果有,请指出我正确的方向。感谢。

  10-01 16:01:11.921: D/dalvikvm(1397): GC_FOR_ALLOC freed 103K, 8%
 free 2808K/3028K, paused 37ms, total 39ms 10-01 16:01:11.921:
 I/dalvikvm-heap(1397): Grow heap (frag case) to 3.460MB for
 635812-byte allocation 10-01 16:01:12.041: D/dalvikvm(1397):
 GC_FOR_ALLOC freed 3K, 7% free 3426K/3652K, paused 114ms, total 114ms
 10-01 16:01:12.291: D/gralloc_goldfish(1397): Emulator without GPU
 emulation detected. 10-01 16:01:12.491: D/AndroidRuntime(1397):
 Shutting down VM 10-01 16:01:12.511: W/dalvikvm(1397): threadid=1:
 thread exiting with uncaught exception (group=0x41465700) 10-01
 16:01:12.581: E/AndroidRuntime(1397): FATAL EXCEPTION: main 10-01
 16:01:12.581: E/AndroidRuntime(1397): java.lang.NullPointerException
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 com.commonsware.empublite.BookContents.getChapterCount(BookContents.java:16)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 com.commonsware.empublite.ContentsAdapter.getCount(ContentsAdapter.java:26)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 android.support.v4.view.ViewPager.setAdapter(ViewPager.java:434) 10-01
 16:01:12.581: E/AndroidRuntime(1397):  at
 com.commonsware.empublite.EmPubLiteActivity.setupPager(EmPubLiteActivity.java:70)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 com.commonsware.empublite.ModelFragment.deliverModel(ModelFragment.java:29)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 com.commonsware.empublite.ModelFragment.access$2(ModelFragment.java:27)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 com.commonsware.empublite.ModelFragment$ContentsLoadTask.onPostExecute(ModelFragment.java:82)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 com.commonsware.empublite.ModelFragment$ContentsLoadTask.onPostExecute(ModelFragment.java:1)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 android.os.AsyncTask.finish(AsyncTask.java:631) 10-01 16:01:12.581:
 E/AndroidRuntime(1397):    at
 android.os.AsyncTask.access$600(AsyncTask.java:177) 10-01
 16:01:12.581: E/AndroidRuntime(1397):  at
 android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 android.os.Handler.dispatchMessage(Handler.java:99) 10-01
 16:01:12.581: E/AndroidRuntime(1397):  at
 android.os.Looper.loop(Looper.java:137) 10-01 16:01:12.581:
 E/AndroidRuntime(1397):    at
 android.app.ActivityThread.main(ActivityThread.java:5103) 10-01
 16:01:12.581: E/AndroidRuntime(1397):  at
 java.lang.reflect.Method.invokeNative(Native Method) 10-01
 16:01:12.581: E/AndroidRuntime(1397):  at
 java.lang.reflect.Method.invoke(Method.java:525) 10-01 16:01:12.581:
 E/AndroidRuntime(1397):    at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
 10-01 16:01:12.581: E/AndroidRuntime(1397):    at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-01
 16:01:12.581: E/AndroidRuntime(1397):  at
 dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

  

我不清楚我的logcat文件中要查找的内容

这将是您崩溃的例外和行:

10-01 16:01:12.581: E/AndroidRuntime(1397): FATAL EXCEPTION: main
10-01 16:01:12.581: E/AndroidRuntime(1397): java.lang.NullPointerException
10-01 16:01:12.581: E/AndroidRuntime(1397): at com.commonsware.empublite.BookContents.getChapterCount(BookContents.java:16) 

因此,您在BookContents.javagetChapterCount()方法中的BookContents第16行崩溃。

该方法应如下所示:

  int getChapterCount() {
    return(chapters.length());
  }

这表明:

  1. 您缺少构造函数中的chapters=raw.optJSONArray("chapters");行,或

  2. 您的JSON缺少chapters数组

  3. Here is a working implementation of Tutorial 12,包括the BookContents class