1

每次在 AVD 上运行我的 android 应用程序时,我都会收到以下错误。该应用程序在运行时几乎立即崩溃:

    08-24 02:18:01.629: E/AndroidRuntime(1860): FATAL EXCEPTION: main
08-24 02:18:01.629: E/AndroidRuntime(1860): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.zamani.randomizedworkout/com.zamani.randomizedworkout.MainScreen}: java.lang.ClassNotFoundException: Didn't find class "com.zamani.randomizedworkout.MainScreen" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.zamani.randomizedworkout-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.zamani.randomizedworkout-2, /system/lib]]
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.os.Looper.loop(Looper.java:137)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.app.ActivityThread.main(ActivityThread.java:5103)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at java.lang.reflect.Method.invoke(Method.java:525)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at dalvik.system.NativeStart.main(Native Method)
08-24 02:18:01.629: E/AndroidRuntime(1860): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.zamani.randomizedworkout.MainScreen" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.zamani.randomizedworkout-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.zamani.randomizedworkout-2, /system/lib]]
08-24 02:18:01.629: E/AndroidRuntime(1860):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
08-24 02:18:01.629: E/AndroidRuntime(1860):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
08-24 02:18:01.629: E/AndroidRuntime(1860):     ... 11 more

另外,这是我的 AndroidManifest:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.zamani.randomizedworkout" />

    <application>
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="android.test.runner" />
        <activity
            android:name="com.zamani.randomizedworkout"
            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="com.zamani.randomizedworkout.WorkoutScreen"
            android:label="com.zamani.randomizedworkout.MyActivityLib:string/app_name" >
        </activity>
    </application>

</manifest>

关于我的问题的一些附加信息:我已将我的两个活动都包含在我的 AndroidManifest 中,如上所示,所以除非我遗漏了什么,否则我不确定这是我遇到的问题。我的应用程序运行良好,直到几天前我将 SDK 版本从 17 升级到 18,所以这可能是我的问题的一部分。我检查了其他几个有关类似问题的 StackOverflow 线程,但没有找到解决我问题的解决方案。任何帮助将不胜感激!

4

2 回答 2

1

尝试这个:

        <activity
            android:name="com.zamani.randomizedworkout.MainScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
于 2013-08-24T07:42:59.697 回答
0

我有类似的问题,但安装我的应用程序后重新启动设备解决了这个问题。但现在的问题是,我每次都必须这样做才能运行应用程序。

于 2013-11-18T06:40:04.897 回答