Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGraham Shunk
1,097 Pointsemulator problem
hey, I have gotten all of the code right so I am not worried about that, but when I try to run the app it just says "Unfortunately, FunFacts has stopped running". I keep trying to click on it in the emulator, but it just doesn't work. I am really anxious to see the app work on my own computer, so any help would greatly appreciated. Thanks!
2 Answers
Kunle Ogunjimi
3,126 PointsFirst try look at the logcat. It could be a number of things that is casuing it to crash, variable being set to null or method returning null in your main activity but try some debugging. You could do some Log.d(TAG, "message"); in your main activity see if oncreate is throwing an error, here is good place to start learning to debug https://developer.android.com/studio/debug/index.html
if you could print out your Log output on here it will also help.
Graham Shunk
1,097 PointsI have found the logcat and this is all that it says:
06-13 14:43:53.213 4414-4414/treehouse.com.funfacts I/art: Not late-enabling -Xcheck:jni (already on) 06-13 14:43:53.214 4414-4414/treehouse.com.funfacts I/art: Late-enabling JIT 06-13 14:43:53.321 4414-4414/treehouse.com.funfacts I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
06-13 14:43:53.585 4414-4414/treehouse.com.funfacts W/System: ClassLoader referenced unknown path: /data/app/treehouse.com.funfacts-1/lib/x86
06-13 14:43:54.198 4414-4421/treehouse.com.funfacts W/art: Suspending all threads took: 56.582ms 06-13 14:43:54.560 4414-4414/treehouse.com.funfacts D/AndroidRuntime: Shutting down VM 06-13 14:43:54.561 4414-4414/treehouse.com.funfacts E/AndroidRuntime: FATAL EXCEPTION: main
Process: treehouse.com.funfacts, PID: 4414 java.lang.RuntimeException: Unable to start activity ComponentInfo{treehouse.com.funfacts/treehouse.com.funfacts.FunFactsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at treehouse.com.funfacts.FunFactsActivity.onCreate(FunFactsActivity.java:32) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 06-13 14:43:58.074 4414-4414/treehouse.com.funfacts I/Process: Sending signal. PID: 4414 SIG: 9
do you think you "decrypt" what the problem is.
Sagar Suri
6,043 PointsU didn't initialize the button event listener properly: Write like this: buttonName.setOnClickListener(new View.OnClickListener(){ //write your code here };
Sagar Suri
6,043 PointsSagar Suri
6,043 PointsRead the logcat while your app is crashing. While running on emulator just keep an eye on the logcat. Click on your app and see the error in the logcat