每次在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线程,但没有找到解决我的问题的解决方案。任何帮助将不胜感激!
最佳答案
尝试这个:
<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>
关于android - Android RunTimeError:Java.lang.RunTimeException:无法实例化 Activity ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18416209/