Java – Unfortunately my first application stopped in the emulator

Unfortunately my first application stopped in the emulator… here is a solution to the problem.

Unfortunately my first application stopped in the emulator

I am trying the first tutorial on the official Android website. This is to display a message when I hit send, but I get an error when I hit send.

I’ve tried some questions like this but I can’t find the answer to my question

I have little experience with Java and Android.

Error log:

12-18 18:56:33.421: W/Trace(1004): Unexpected value from nativeGetEnabledTags: 0
12-18 18:56:33.421: W/Trace(1004): Unexpected value from nativeGetEnabledTags: 0
12-18 18:56:33.450: W/Trace(1004): Unexpected value from nativeGetEnabledTags: 0
12-18 18:56:33.480: D/AndroidRuntime(1004): Shutting down VM
12-18 18:56:33.490: W/dalvikvm(1004): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-18 18:56:33.520: E/AndroidRuntime(1004): FATAL EXCEPTION: main
12-18 18:56:33.520: E/AndroidRuntime(1004): java.lang.IllegalStateException: Could not execute method of the activity
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.view.View$1.onClick(View.java:3597)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.view.View.performClick(View.java:4202)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.view.View$PerformClick.run(View.java:17340)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.os.Handler.handleCallback(Handler.java:725)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.os.Looper.loop(Looper.java:137)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.app.ActivityThread.main(ActivityThread.java:5039)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at java.lang.reflect.Method.invoke(Method.java:511)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at dalvik.system.NativeStart.main(Native Method)
12-18 18:56:33.520: E/AndroidRuntime(1004): Caused by: java.lang.reflect.InvocationTargetException
12-18 18:56:33.520: E/AndroidRuntime(1004):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at java.lang.reflect.Method.invoke(Method.java:511)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.view.View$1.onClick(View.java:3592)
12-18 18:56:33.520: E/AndroidRuntime(1004):     ... 11 more
12-18 18:56:33.520: E/AndroidRuntime(1004): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myfirstapp/ com.example.myfirstapp.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml?
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.app.Activity.startActivityForResult(Activity.java:3370)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.app.Activity.startActivityForResult(Activity.java:3331)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.app.Activity.startActivity(Activity.java:3566)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at android.app.Activity.startActivity(Activity.java:3534)
12-18 18:56:33.520: E/AndroidRuntime(1004):     at com.example.myfirstapp.MainActivity.sendMessage(MainActivity.java:37)
12-18 18:56:33.520: E/AndroidRuntime(1004):     ... 14 more
12-18 18:56:37.129: I/Process(1004): Sending signal. PID: 1004 SIG: 9

Solution

Unable to find explicit activity class
{com.example.myfirstapp/com.example.myfirstapp.DisplayMessageActivity};
have you declared this activity in your AndroidManifest.xml?

So make sure you’ve declared the DisplayMessageActivity in your AndroidManifest as:

<activity 
   android:name="com.example.myfirstapp.DisplayMessageActivity">
</activity>

Related Problems and Solutions