每次在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线程,但我没有找到解决我问题的解决方案。任何帮助将不胜感激!
答案 0 :(得分: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>
答案 1 :(得分:0)
我遇到了类似的问题,但在安装我的应用程序后重新启动设备解决了这个问题。但现在问题是,我每次都必须这样做才能运行应用程序。