我最近使用 Eclipse 的重构命令重构了我的应用程序(目前称为 MyApp)中的类、包和文件夹名称,但我没有收到 ClassNotFoundException。我确保代码库中的任何地方都不再有旧名称的实例。我还删除了其中的所有类文件\bin\classes
并在其中生成了 Java 文件\gen
(这两个文件都已重新生成,我已经检查过)。为了解决这个问题,我还将 API 级别从 16 更新到了 17。这是堆栈跟踪:
12-22 17:00:46.690: E/AndroidRuntime(25466): FATAL EXCEPTION: main
12-22 17:00:46.690: E/AndroidRuntime(25466): java.lang.RuntimeException: Unable to instantiate application com.myapp.MyApp: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyApp" on path: /data/app/com.myapp-2.apk
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.os.Looper.loop(Looper.java:137)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.reflect.Method.invokeNative(Native Method)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.reflect.Method.invoke(Method.java:511)
12-22 17:00:46.690: E/AndroidRuntime(25466): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-22 17:00:46.690: E/AndroidRuntime(25466): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-22 17:00:46.690: E/AndroidRuntime(25466): at dalvik.system.NativeStart.main(Native Method)
12-22 17:00:46.690: E/AndroidRuntime(25466): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyApp" on path: /data/app/com.myapp-2.apk
12-22 17:00:46.690: E/AndroidRuntime(25466): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.Instrumentation.newApplication(Instrumentation.java:968)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
12-22 17:00:46.690: E/AndroidRuntime(25466): ... 11 more
这是我的清单。我知道硬编码字符串是不好的风格。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
android:name="MyApp"
android:label="MyApp"
android:theme="@style/NoActionBar">
<activity
android:name=".Otheractivity"
android:label="Otheractivity">
</activity>
<activity
android:name=".MainMenu"
android:label="MainMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
关于问题可能是什么的任何想法?