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 trial

Android Build a Simple Android App (2014) Basic Android Programming Adding the onClick() Method

Tried to run my app and got the message, "Unfortunately, Fun Facts has stopped.", any ideas?

When I try to run my app, I get the following message on the emulator,"Unfortunately, Fun Facts has stopped." I am not getting any errors anywhere that I can find. I tried a few times and keep getting the same result.

Kate Hoferkamp
Kate Hoferkamp
5,205 Points

The error for why the program force stopped is in the LogCat. Open that up and let us know what the error showing is, then we can help you out further =]

9 Answers

I have tried several times so the logcat message is long. What part of it do you want?

Kate Hoferkamp
Kate Hoferkamp
5,205 Points

Are you sure you are looking in the right place..? If you run the program, it is impossible for logCat to be empty, even if the run is successful.

It did finally show up. Here is the last portion of it. I don't know why there was such a delay.

10-06 15:00:39.906 388-432/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg 10-06 15:00:39.906 388-432/? W/AudioService﹕ onLoadSoundEffects(), Error -1 while loading samples 10-06 15:00:39.926 388-562/? W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b24a09a8 attribute=null, token = android.os.BinderProxy@b209d200 10-06 15:00:40.026 388-563/? I/ActivityManager﹕ Process com.kimberlyhoshal.corgifunfacts (pid 1142) has died. 10-06 15:00:40.066 388-640/? D/LightsService﹕ Excessive delay setting light: 116ms 10-06 15:00:40.136 388-640/? D/LightsService﹕ Excessive delay setting light: 67ms 10-06 15:01:32.596 388-451/? D/LightsService﹕ Excessive delay setting light: 63ms 10-06 15:01:32.656 388-451/? D/LightsService﹕ Excessive delay setting light: 66ms 10-06 15:01:32.726 388-451/? D/LightsService﹕ Excessive delay setting light: 63ms 10-06 15:01:32.796 388-640/? D/LightsService﹕ Excessive delay setting light: 67ms 10-06 15:01:32.886 388-451/? D/LightsService﹕ Excessive delay setting light: 72ms 10-06 15:01:32.956 388-451/? D/LightsService﹕ Excessive delay setting light: 71ms 10-06 15:01:33.026 388-451/? D/LightsService﹕ Excessive delay setting light: 70ms 10-06 15:01:33.096 388-451/? D/LightsService﹕ Excessive delay setting light: 68ms

Boris Vukobrat
Boris Vukobrat
4,248 Points

Referring to original post, I suggest you restart everything. It looks to me like your emulator disconnected from IDE.

You can't run (and build) an App without device connected, but you can clean and rebuild it. There isn't Logcat when a device is not connected. Also, as had happened to me in some occasions, Genymotion emulator disconnected from Android Studio.

The device was connected and showed up. There was no error messages showing in the code. In logcat, this is the only error message I could find in red.....E/PerformBackupTask﹕ Error invoking for backup on @pm@

I have tried cleaning, rebuilding, and using a new emulator. Still nothing. Here is one of the error messages that show up when I started the emulator. 384-419/system_process E/NetdConnector﹕ NDC Command {59 bandwidth removeiquota eth0} took too long (609ms) When I tried to run the app, I got this 10-07 19:46:35.032 1079-1079/com.kimberlyhoshal.corgifunfacts E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.kimberlyhoshal.corgifunfacts, PID: 1079 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kimberlyhoshal.corgifunfacts/com.kimberlyhoshal.corgifunfacts.CorgiFunFactsActivity}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button at com.kimberlyhoshal.corgifunfacts.CorgiFunFactsActivity.onCreate(CorgiFunFactsActivity.java:21) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)             at android.app.ActivityThread.access$800(ActivityThread.java:135)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:136)             at android.app.ActivityThread.main(ActivityThread.java:5017)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:515)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)             at dalvik.system.NativeStart.main(Native Method) 10-07 19:46:45.202 1079-1079/com.kimberlyhoshal.corgifunfacts I/Process﹕

Cleaned and rebuilt. I get the following error in logcat:

Caused by: java.lang.NullPointerException at ...MainActivity.onCreate(MainActivity.java:53)

Line 53: showFactButton.setOnClickListener(listener);

Any idea on how to solve this?

Boris Vukobrat
Boris Vukobrat
4,248 Points

Kimberly, at the first message you noted "no messages" which referred me to disconnected emulator. In your activity class CorgiFunFactsActivity at line 21, you have a cast error, trying to assign ImageButton widget to a Button widget.

Not showing an error in the code portion, so I am not sure how to fix this. Any help is appreciated. Extreme novice.

Here is the line of code as I am seeing it... Button showFactButton = (Button) findViewById(R.id.showfactButton);

Boris Vukobrat
Boris Vukobrat
4,248 Points

Aditya, it seems your showfactButton object is empty.

I suggest you enter exact code as in lesson, so you can easily find where is your mistake. In lesson showFactButton.setOnClickListener(listener); is at line 30, so I wonder what do you have at additional 23 lines.

Fixed it!