我相信造成它的原因是堆栈跟踪。
我将在此处查看官方Android应用程序扩展教程:https://developer.android.com/training/index.html
我完成了#34;开始另一项活动"部分,并在尝试测试时发现此错误。我也无法在本教程的前面部分运行该应用程序。
这导致我找到了这个链接:Unfortunately MyApp has stopped. How can I solve this?
这让我想到了这个链接: What is a stack trace, and how can I use it to debug my application errors?
但我仍然无法搞清楚。
以下是错误日志的片段:
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
有关如何解决此问题的任何建议?谢谢!
编辑:
我相信这是我的清单文件:
<?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>
答案 0 :(得分:0)
您的清单中有不正确的结束标记:
<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>
这是没有打开标记的错误结束标记:
<!-- The meta-data tag is required if you support API level 15 and lower -->
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
尝试删除它。
<强>已更新强>:
在教程中,您遗漏了<meta-data
的开放标记,因此您需要通过添加开放标记来更正它:
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" />
添加标记后,您的代码将如下所示:
<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>