Android Studio:如何在模拟器中调试显示错误“Unfortunetly,App已停止工作”的Android应用程序?

时间:2016-11-28 07:03:30

标签: android android-studio ide

当我尝试在Android Studio模拟器中运行我的应用程序时出现以下错误“不幸的是,App已停止工作”。最初,我的Manifest文件存在一些问题,其中android:theme未设置为AppCompat且我的活动路径不正确。但是,在修复这些问题后,我在logcat中遇到以下异常:

     --------- beginning of crash
FATAL EXCEPTION: main
                                                                             Process: PID: 2437
                                                                             java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.MyApp/main.AuthenticationActivity}: java.lang.ClassNotFoundException: Didn't find class "main.AuthenticationActivity" on path: DexPathList[[zip file "/data/app/com.android.MyApp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                                 at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:135)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                              Caused by: java.lang.ClassNotFoundException: Didn't find class "main.AuthenticationActivity" on path: DexPathList[[zip file "/data/app/com.android.MyApp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
                                                                                 at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                                 at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                                 at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:135) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

这是我的AndroidManifest文件:

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


    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    <uses-permission android:name="android.permission.READ_PROFILE"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat">
        <activity android:name="main.AuthenticationActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="main.HomeActivity"
                  android:label="@string/app_name">
        </activity>
    </application>

</manifest>

我浏览了与本网站相关的所有帖子,并尽力清楚地表达我的问题。我还是新手,所以我对所有建设性的批评持开放态度。

根据我的理解,它说它无法找到主要活动的文件路径,我再次检查我在所有文件上输入了正确的文件路径。任何帮助将非常感激。

1 个答案:

答案 0 :(得分:0)

将清单中的代码更改为:“main.AuthenticationActivity”改为“.main.AuthenticationActivity”。