简体   繁体   中英

In Android Studio, when I try to launch my app, it says “My First App has stopped” in the Android emulator

I believe what is causing it is a stack trace.

I am going through the official Android app bulding tutorial here: https://developer.android.com/training/index.html

I finished the "Start Another Activity" section and have found this error while trying to test it. I was also not able to run the app in the earlier parts of the tutorial.

That led me to this link: Unfortunately MyApp has stopped. How can I solve this?

Which led me to this link: What is a stack trace, and how can I use it to debug my application errors?

But I am still having trouble figuring it out.

Here is a snippet of the error log:

12-14 09:52:06.962 3696-3696/com.example.myfirstapp I/zygote:     at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
12-14 09:52:06.962 3696-3696/com.example.myfirstapp I/zygote:     at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
12-14 09:52:06.962 3696-3696/com.example.myfirstapp I/zygote:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:807)
12-14 09:52:06.962 3696-3696/com.example.myfirstapp D/AndroidRuntime: Shutting down VM
12-14 09:52:06.964 3696-3696/com.example.myfirstapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: com.example.myfirstapp, PID: 3696
                                                                      java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/base.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/lib/x86, /system/lib, /vendor/lib]]
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                                                                          at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                          at android.os.Looper.loop(Looper.java:164)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6494)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                                                                       Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/base.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/lib/x86, /system/lib, /vendor/lib]]
                                                                          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                          at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                                                                          at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                          at android.os.Looper.loop(Looper.java:164) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6494) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
                                                                        Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
                                                                          at java.lang.VMClassLoader.findLoadedClass(Native Method)
                                                                          at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
12-14 09:52:06.964 3696-3696/com.example.myfirstapp E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
                                                                                ... 12 more
                                                                       Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/base.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/lib/x86, /system/lib, /vendor/lib]]
                                                                          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                ... 15 more

Any suggestions on how to figure this out? Thanks!

Edit:

I believe this is my Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".DisplayMessageActivity"
            android:parentActivityName=".MainActivity" >
            <!-- The meta-data tag is required if you support API level 15 and lower -->
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
        </activity>
    </application>

</manifest>

You have incorrect closing tag in your manifest:

<activity android:name=".DisplayMessageActivity"
    android:parentActivityName=".MainActivity" >
    <!-- The meta-data tag is required if you support API level 15 and lower -->
    android:name="android.support.PARENT_ACTIVITY"
    android:value=".MainActivity" />
</activity>

This is the incorrect closing tag without open tag:

    <!-- The meta-data tag is required if you support API level 15 and lower -->
    android:name="android.support.PARENT_ACTIVITY"
    android:value=".MainActivity" />

Try removing it.

UPDATED :

From the tutorial, you're missing the open tag of <meta-data , so you need to correct it by adding the open tag:

<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" />

After adding the tag, your code will be like this:

<activity android:name=".DisplayMessageActivity"
    android:parentActivityName=".MainActivity" >
    <!-- The meta-data tag is required if you support API level 15 and lower -->
    <meta-data android:name="android.support.PARENT_ACTIVITY"
    android:value=".MainActivity" />
</activity>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM