Unfortunately GeoQuiz has stopped


#1

I can’t figure out why it’s not working. :frowning:
It was working before the refactoring in Chapter 2.
Here is my error log. Anyone familiar with this?

05-18 21:47:26.877: D/dalvikvm(403): GC_FOR_ALLOC freed 1006K, 14% free 7324K/8504K, paused 53ms, total 57ms
05-18 21:47:27.086: D/dalvikvm(403): GC_FOR_ALLOC freed 12K, 14% free 7674K/8856K, paused 85ms, total 86ms
05-18 21:47:27.208: D/dalvikvm(403): GC_FOR_ALLOC freed 2K, 13% free 7948K/9124K, paused 58ms, total 58ms
05-18 21:47:27.497: I/Choreographer(403): Skipped 82 frames!  The application may be doing too much work on its main thread.
05-18 21:47:27.657: D/dalvikvm(403): GC_FOR_ALLOC freed 888K, 16% free 8338K/9896K, paused 68ms, total 72ms
05-18 21:47:27.697: I/ActivityManager(287): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.bignerdranch.android.geoquiz/.QuizActivity} from pid 403
05-18 21:47:27.996: D/dalvikvm(287): GC_FOR_ALLOC freed 962K, 16% free 9252K/10920K, paused 225ms, total 240ms
05-18 21:47:27.996: I/dalvikvm-heap(287): Grow heap (frag case) to 9.514MB for 380496-byte allocation
05-18 21:47:28.126: D/dalvikvm(287): GC_FOR_ALLOC freed 109K, 16% free 9514K/11292K, paused 124ms, total 124ms
05-18 21:47:28.336: D/dalvikvm(403): GC_FOR_ALLOC freed 425K, 14% free 8857K/10228K, paused 182ms, total 204ms
05-18 21:47:28.376: I/Choreographer(403): Skipped 48 frames!  The application may be doing too much work on its main thread.
05-18 21:47:28.438: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
05-18 21:47:28.648: D/dalvikvm(403): GC_FOR_ALLOC freed 210K, 15% free 9164K/10744K, paused 224ms, total 225ms
05-18 21:47:28.667: I/dalvikvm-heap(403): Grow heap (frag case) to 10.630MB for 1644560-byte allocation
05-18 21:47:28.716: W/ActivityManager(287): Activity pause timeout for ActivityRecord{40f75b10 u0 com.android.launcher/com.android.launcher2.Launcher}
05-18 21:47:28.747: D/dalvikvm(921): Not late-enabling CheckJNI (already on)
05-18 21:47:28.767: I/ActivityManager(287): Start proc com.bignerdranch.android.geoquiz for activity com.bignerdranch.android.geoquiz/.QuizActivity: pid=921 uid=10050 gids={50050, 1028}
05-18 21:47:28.807: D/dalvikvm(403): GC_FOR_ALLOC freed 331K, 16% free 10439K/12352K, paused 130ms, total 135ms
05-18 21:47:29.116: E/Trace(921): error opening trace file: No such file or directory (2)
05-18 21:47:29.527: W/Resources(921): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080000}
05-18 21:47:29.627: D/AndroidRuntime(921): Shutting down VM
05-18 21:47:29.627: W/dalvikvm(921): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-18 21:47:29.646: E/AndroidRuntime(921): FATAL EXCEPTION: main
05-18 21:47:29.646: E/AndroidRuntime(921): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.geoquiz/com.bignerdranch.android.geoquiz.QuizActivity}: java.lang.NullPointerException
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.os.Looper.loop(Looper.java:137)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.ActivityThread.main(ActivityThread.java:5041)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at java.lang.reflect.Method.invokeNative(Native Method)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at java.lang.reflect.Method.invoke(Method.java:511)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at dalvik.system.NativeStart.main(Native Method)
05-18 21:47:29.646: E/AndroidRuntime(921): Caused by: java.lang.NullPointerException
05-18 21:47:29.646: E/AndroidRuntime(921): 	at com.bignerdranch.android.geoquiz.QuizActivity.updateQuestion(QuizActivity.java:30)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at com.bignerdranch.android.geoquiz.QuizActivity.onCreate(QuizActivity.java:69)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.Activity.performCreate(Activity.java:5104)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-18 21:47:29.646: E/AndroidRuntime(921): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-18 21:47:29.646: E/AndroidRuntime(921): 	... 11 more
05-18 21:47:29.667: W/ActivityManager(287):   Force finishing activity com.bignerdranch.android.geoquiz/.QuizActivity
05-18 21:47:29.908: D/dalvikvm(287): GC_FOR_ALLOC freed 827K, 22% free 8826K/11292K, paused 122ms, total 125ms
05-18 21:47:30.156: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
05-18 21:47:30.447: W/ActivityManager(287): Activity pause timeout for ActivityRecord{412aeee0 u0 com.bignerdranch.android.geoquiz/.QuizActivity}
05-18 21:47:31.226: D/dalvikvm(403): GC_FOR_ALLOC freed 727K, 15% free 10585K/12352K, paused 128ms, total 129ms
05-18 21:47:31.356: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
05-18 21:47:31.387: W/EGL_emulation(403): eglSurfaceAttrib not implemented
05-18 21:47:31.717: I/ActivityManager(287): No longer want com.android.music (pid 545): empty #17
05-18 21:47:32.146: D/dalvikvm(403): GC_FOR_ALLOC freed 1878K, 23% free 9725K/12572K, paused 52ms, total 56ms
05-18 21:47:32.437: D/dalvikvm(403): GC_CONCURRENT freed 1342K, 18% free 10399K/12572K, paused 6ms+5ms, total 71ms
05-18 21:47:32.437: D/dalvikvm(403): WAIT_FOR_CONCURRENT_GC blocked 46ms
05-18 21:47:33.176: I/Process(921): Sending signal. PID: 921 SIG: 9
05-18 21:47:33.196: I/ActivityManager(287): Process com.bignerdranch.android.geoquiz (pid 921) has died.
05-18 21:47:33.336: W/InputMethodManagerService(287): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4103f500 attribute=null, token = android.os.BinderProxy@41175ba8
05-18 21:48:49.427: E/ThrottleService(287): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
05-18 21:50:18.287: I/ActivityManager(287): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.bignerdranch.android.geoquiz/.QuizActivity} from pid 403
05-18 21:50:18.647: D/dalvikvm(935): Not late-enabling CheckJNI (already on)
05-18 21:50:18.682: I/ActivityManager(287): Start proc com.bignerdranch.android.geoquiz for activity com.bignerdranch.android.geoquiz/.QuizActivity: pid=935 uid=10050 gids={50050, 1028}
05-18 21:50:18.687: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
05-18 21:50:19.076: E/Trace(935): error opening trace file: No such file or directory (2)
05-18 21:50:19.467: W/Resources(935): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080000}
05-18 21:50:19.517: D/AndroidRuntime(935): Shutting down VM
05-18 21:50:19.517: W/dalvikvm(935): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-18 21:50:19.548: E/AndroidRuntime(935): FATAL EXCEPTION: main
05-18 21:50:19.548: E/AndroidRuntime(935): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.geoquiz/com.bignerdranch.android.geoquiz.QuizActivity}: java.lang.NullPointerException
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.os.Looper.loop(Looper.java:137)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.ActivityThread.main(ActivityThread.java:5041)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at java.lang.reflect.Method.invokeNative(Native Method)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at java.lang.reflect.Method.invoke(Method.java:511)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at dalvik.system.NativeStart.main(Native Method)
05-18 21:50:19.548: E/AndroidRuntime(935): Caused by: java.lang.NullPointerException
05-18 21:50:19.548: E/AndroidRuntime(935): 	at com.bignerdranch.android.geoquiz.QuizActivity.updateQuestion(QuizActivity.java:30)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at com.bignerdranch.android.geoquiz.QuizActivity.onCreate(QuizActivity.java:69)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.Activity.performCreate(Activity.java:5104)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-18 21:50:19.548: E/AndroidRuntime(935): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-18 21:50:19.548: E/AndroidRuntime(935): 	... 11 more
05-18 21:50:19.557: W/ActivityManager(287):   Force finishing activity com.bignerdranch.android.geoquiz/.QuizActivity
05-18 21:50:19.796: D/dalvikvm(287): GC_FOR_ALLOC freed 1023K, 21% free 8929K/11292K, paused 126ms, total 141ms
05-18 21:50:20.106: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
05-18 21:50:20.327: W/ActivityManager(287): Activity pause timeout for ActivityRecord{413e3ef0 u0 com.bignerdranch.android.geoquiz/.QuizActivity}
05-18 21:50:20.437: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
05-18 21:50:20.497: W/EGL_emulation(403): eglSurfaceAttrib not implemented
05-18 21:50:22.477: I/Process(935): Sending signal. PID: 935 SIG: 9
05-18 21:50:22.487: I/ActivityManager(287): Process com.bignerdranch.android.geoquiz (pid 935) has died.
05-18 21:50:22.637: W/InputMethodManagerService(287): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40f8d2f0 attribute=null, token = android.os.BinderProxy@41175ba8

#2

It looks like you’ve got a NullPointerException in updateQuestion, on line 30. (Skip ahead to the Debugging chapter if you want to see this for yourself) You should be able to see which object was null if you check that line in your code.


#3

The code is exactly the same as on the book.
I just switched machines and redid the whole thing and it works.


#4

Well, that’s one way to figure it out. :slight_smile: Glad to hear you solved the problem.


#5

Having same issue - no compilation warnings or error, code is exact match to book, code looks right. All the TrueFalse stuff looks right.

NullPointerException thrown on .setText below. mQuestionTextView is properly defined

I recreated the AVD with same results.

User: “ojbux1”: When you say “switched machines” - did you create a different AVD or reinstall ADT on another computer?

[color=#FF4000] private int mCurrentIndex=0;

private void updateQuestion() {
    int question=mQuestionBank[mCurrentIndex].getQuestion();
    mQuestionTextView.setText(question);[/color]

JonathanW


#6

Two things:

1- Make sure you’re calling findViewById to assign mQuestionTextView.

2- Make sure that mQuestionTextView is not null after calling findViewById. If it still null, that means that your layout file does not have a TextView with the id you are trying to find.


#7

Thanks. I had deleted the mQuestionTextView assignment. Really should have seen that myself.

Thanks again for your prompt response.

Jonathan