我刚刚将应用程序重构为框架库和应用程序,但是现在当我尝试在模拟器中启动该应用程序时,我得到了以下错误堆栈跟踪:
06-02 18:22:35.529: E/AndroidRuntime(586): FATAL EXCEPTION: main
06-02 18:22:35.529: E/AndroidRuntime(586): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.matthewrathbone.eastersays/com.matthewrathbone.eastersays.EasterSimonSaysActivity}: java.lang.ClassNotFoundException: com.matthewrathbone.eastersays.EasterSimonSaysActivity in loader dalvik.system.PathClassLoader[/data/app/com.matthewrathbone.eastersays-1.apk]
06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.os.Looper.loop(Looper.java:123)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 18:22:35.529: E/AndroidRuntime(586): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 18:22:35.529: E/AndroidRuntime(586): at java.lang.reflect.Method.invoke(Method.java:521)
06-02 18:22:35.529: E/AndroidRuntime(586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-02 18:22:35.529: E/AndroidRuntime(586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-02 18:22:35.529: E/AndroidRuntime(586): at dalvik.system.NativeStart.main(Native Method)
06-02 18:22:35.529: E/AndroidRuntime(586): Caused by: java.lang.ClassNotFoundException: com.matthewrathbone.eastersays.EasterSimonSaysActivity in loader dalvik.system.PathClassLoader[/data/app/com.matthewrathbone.eastersays-1.apk]
06-02 18:22:35.529: E/AndroidRuntime(586): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-02 18:22:35.529: E/AndroidRuntime(586): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-02 18:22:35.529: E/AndroidRuntime(586): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
06-02 18:22:35.529: E/AndroidRuntime(586): ... 11 more
通常这意味着清单文件在某种程度上是错误的,但是我已经仔细检查了所有我能想到的内容。
这是我的活动课:
package com.matthewrathbone.eastersays;
import android.os.Bundle;
import com.rathboma.simonsays.Assets.Season;
import com.rathboma.simonsays.SeasonPicker;
import com.rathboma.simonsays.SimonSaysActivity;
public class EasterSimonSaysActivity extends SimonSaysActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
public SeasonPicker getSeasonPicker() {
return new SeasonPicker(){
@Override
public Season getSeason() {
// TODO Auto-generated method stub
return Season.EASTER;
}
};
}
}
如您所见,清单中正确列出了它:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.matthewrathbone.eastersays"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".EasterSimonSaysActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我不知道如何解决此问题,不胜感激。我已经在SO上扫描了许多类似的问题,而没有看到这种特殊的行为。
更多信息:
- 我已经检查了生成的APK,并且该类在classes.dex文件中有一个条目
- 我曾尝试在Eclipse中清理/构建项目
- 我尝试使用全新的设备映像,但该映像上没有APK的副本
- 我已将库项目更改为常规的Java,然后又更改为android项目,没有区别
- 将抽象的SimonSaysActivity添加到清单没有区别。
- 我尝试将每个依赖项都设为一个android库项目,并同步他们需要的android版本,但这样做没有帮助
找到了解决方案(见下文)。对于每个发表了答案/评论的人:你们都很高兴,感谢您帮助我解决问题!
看起来是SDK工具升级引入的。感谢以下在此链接的注释中的@Nick:http ://iqadd.com/item/noclassdeffounderror-adt-fix