Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Error: "Unfortunately Crystal Ball has stopped working" in the emulator

I've restarted the emulator many times but the app won't run. There are no errors showing in the Console in Eclipse - that shows 'good' messages - but nothing happens at all inside the emulator. When I start the app inside the emulator I just get the "Unfortunately Crystal Ball has stopped" message.

Any ideas to help out would be great!

13 Answers

The problem is on the first line ;)

MainActivity should extend Activity and not ActionBarActivity.

It should be:

 public class MainActivity extends Activity {

You should look in LogCat what caused the app to crash. If you can't resolve it by yourself from the logs, feel free to post the error logs from LogCat here. I am pretty sure somebody will be able to help you.

Thanks Martin.

LogCat is a busy place!

Console gives me:

014-05-15 16:21:42 - CrystalBall] Android Launch! [2014-05-15 16:21:42 - CrystalBall] adb is running normally. [2014-05-15 16:21:42 - CrystalBall] Performing uk.co.bigdogconsultants.crystalball.MainActivity activity launch [2014-05-15 16:21:42 - CrystalBall] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Android44' [2014-05-15 16:21:42 - CrystalBall] Uploading CrystalBall.apk onto device 'emulator-5554' [2014-05-15 16:21:43 - CrystalBall] Installing CrystalBall.apk... [2014-05-15 16:21:56 - CrystalBall] Success! [2014-05-15 16:21:56 - CrystalBall] Starting activity uk.co.bigdogconsultants.crystalball.MainActivity on device emulator-5554

Which all seems fine.

LogCat has all sorts in it:

05-15 11:23:49.058: W/EGL_emulation(554): eglSurfaceAttrib not implemented 05-15 11:23:54.098: E/WindowManager(382): Starting window AppWindowToken{b214e478 token=Token{b2105888 ActivityRecord{b2043268 u0 uk.co.bigdogconsultants.crystalball/.MainActivity t3}}} timed out 05-15 11:23:58.198: I/Process(1072): Sending signal. PID: 1072 SIG: 9 05-15 11:23:58.218: I/ActivityManager(382): Process uk.co.bigdogconsultants.crystalball (pid 1072) has died. 05-15 11:23:58.278: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg 05-15 11:23:58.288: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg 05-15 11:23:58.288: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg 05-15 11:23:58.288: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg

There's pages & pages of that but a 'has died' message looks to be the problem and the timeout before it! I have no idea what any of that means or how to fix it, though.

I suggest you to filter out only the error logs (Level type "E"). Start the app and look for the last ERROR (red) block of logs (it can be a few lines, logs... not just one).

Another attempt had a different message in Console:

[2014-05-15 16:46:03 - CrystalBall] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=uk.co.bigdogconsultants.crystalball/.MainActivity }

This appeared when the emulator went blank then appeared with the error message in the subject.

Thanks again - here's the LogCat filtered to E. Some sort of graphics issue? Did I add the image wrong?

05-15 11:45:59.398: E/memtrack(1096): Couldn't load memtrack module (No such file or directory) 05-15 11:45:59.398: E/android.os.Debug(1096): failed to load memtrack module: -2 05-15 11:46:02.998: E/memtrack(1107): Couldn't load memtrack module (No such file or directory) 05-15 11:46:02.998: E/android.os.Debug(1107): failed to load memtrack module: -2 05-15 11:46:03.728: E/gralloc_goldfish(49): gralloc_alloc: Mismatched usage flags: 328 x 546, usage 333 05-15 11:46:03.728: E/(49): GraphicBufferAlloc::createGraphicBuffer(w=328, h=546) failed (Invalid argument), handle=0x0 05-15 11:46:03.738: E/BufferQueue(382): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed 05-15 11:46:05.328: E/AndroidRuntime(1118): FATAL EXCEPTION: main 05-15 11:46:05.328: E/AndroidRuntime(1118): Process: uk.co.bigdogconsultants.crystalball, PID: 1118 05-15 11:46:05.328: E/AndroidRuntime(1118): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.bigdogconsultants.crystalball/uk.co.bigdogconsultants.crystalball.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.ActivityThread.access$800(ActivityThread.java:135) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.os.Handler.dispatchMessage(Handler.java:102) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.os.Looper.loop(Looper.java:136) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.ActivityThread.main(ActivityThread.java:5017) 05-15 11:46:05.328: E/AndroidRuntime(1118): at java.lang.reflect.Method.invokeNative(Native Method) 05-15 11:46:05.328: E/AndroidRuntime(1118): at java.lang.reflect.Method.invoke(Method.java:515) 05-15 11:46:05.328: E/AndroidRuntime(1118): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 05-15 11:46:05.328: E/AndroidRuntime(1118): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 05-15 11:46:05.328: E/AndroidRuntime(1118): at dalvik.system.NativeStart.main(Native Method) 05-15 11:46:05.328: E/AndroidRuntime(1118): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98) 05-15 11:46:05.328: E/AndroidRuntime(1118): at uk.co.bigdogconsultants.crystalball.MainActivity.onCreate(MainActivity.java:18) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.Activity.performCreate(Activity.java:5231) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 05-15 11:46:05.328: E/AndroidRuntime(1118): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 05-15 11:46:05.328: E/AndroidRuntime(1118): ... 11 more 05-15 11:46:11.298: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg 05-15 11:46:11.308: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg 05-15 11:46:11.308: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg 05-15 11:46:11.318: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg 05-15 11:46:11.388: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg 05-15 11:46:11.388: E/SoundPool(382): error loading /system/media/audio/ui/KeypressStandard.ogg 05-15 11:46:11.438: E/SoundPool(382): error loading /system/media/audio/ui/KeypressSpacebar.ogg 05-15 11:46:11.448: E/SoundPool(382): error loading /system/media/audio/ui/KeypressDelete.ogg 05-15 11:46:11.448: E/SoundPool(382): error loading /system/media/audio/ui/KeypressReturn.ogg 05-15 11:46:11.448: E/SoundPool(382): error loading /system/media/audio/ui/KeypressInvalid.ogg

That's exactly what I was talking about :)

There is a RuntimeException

java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.bigdogconsultants.crystalball/uk.co.bigdogconsultants.crystalball.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

and later it says:

 at uk.co.bigdogconsultants.crystalball.MainActivity.onCreate(MainActivity.java:18)

There is some kind of error on line 18 in your MainActivity class.

I think it is a theme issue, then. Line 18 is:

super.onCreate(savedInstanceState);

The exception seems to be in the theme itself. Odd, as it worked with that theme before.

Could you Copy and Paste the whole MainActivity class? Make sure you use the Markdown CheatSheet under the add new comment dialog (so the code will be readable ;) ).

Alternatively you can try to do a Project Clean in Eclipse. Click "Project" -> "Clean".

Thanks for the replies. i tried the Clean but this didn't fix it.

Here's the code:

public class MainActivity extends ActionBarActivity {

    private CrystalBall mCrystalBall = new CrystalBall();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // declare our View variables
        final TextView answerLabel = (TextView) findViewById(R.id.textView1);
        Button getAnswerButton = (Button) findViewById(R.id.button1);

        getAnswerButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String answer = mCrystalBall.getAnAnswer();

                // update label with dynamic answer
                answerLabel.setText(answer);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Good spot! I've changed that but it still comes up with nothing. LogCat has:

05-15 14:40:28.748: E/PerformBackupTask(382): Error invoking for backup on @pm@
05-15 14:40:28.778: E/PerformBackupTask(382): Duplicate finish
05-15 14:41:16.268: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:16.288: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:16.288: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:16.338: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:16.358: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:16.408: E/SoundPool(382): error loading /system/media/audio/ui/KeypressStandard.ogg
05-15 14:41:16.498: E/SoundPool(382): error loading /system/media/audio/ui/KeypressSpacebar.ogg
05-15 14:41:16.588: E/gralloc_goldfish(49): gralloc_alloc: Mismatched usage flags: 328 x 546, usage 333
05-15 14:41:16.598: E/(49): GraphicBufferAlloc::createGraphicBuffer(w=328, h=546) failed (Invalid argument), handle=0x0
05-15 14:41:16.598: E/BufferQueue(382): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
05-15 14:41:16.608: E/SoundPool(382): error loading /system/media/audio/ui/KeypressDelete.ogg
05-15 14:41:16.648: E/SoundPool(382): error loading /system/media/audio/ui/KeypressReturn.ogg
05-15 14:41:16.648: E/SoundPool(382): error loading /system/media/audio/ui/KeypressInvalid.ogg
05-15 14:41:17.108: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:17.108: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/KeypressStandard.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/KeypressSpacebar.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/KeypressDelete.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/KeypressReturn.ogg
05-15 14:41:17.118: E/SoundPool(382): error loading /system/media/audio/ui/KeypressInvalid.ogg
05-15 14:41:31.798: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:31.798: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/KeypressStandard.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/KeypressSpacebar.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/KeypressDelete.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/KeypressReturn.ogg
05-15 14:41:31.808: E/SoundPool(382): error loading /system/media/audio/ui/KeypressInvalid.ogg
05-15 14:41:31.888: E/gralloc_goldfish(49): gralloc_alloc: Mismatched usage flags: 328 x 546, usage 333
05-15 14:41:31.898: E/(49): GraphicBufferAlloc::createGraphicBuffer(w=328, h=546) failed (Invalid argument), handle=0x0
05-15 14:41:31.898: E/BufferQueue(382): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
05-15 14:41:55.918: E/memtrack(1204): Couldn't load memtrack module (No such file or directory)
05-15 14:41:55.918: E/android.os.Debug(1204): failed to load memtrack module: -2

Is the app still crashing after you launch it?

Sorry - I just looked at all that red stuff in LogCat and assumed it broke. It hadn't - it works fine!

Thank you for lending me your genius for so long. :-)

Steve.