How come I get ClassNotFoundException when backupAgent tries to start
I use the BackupAgentHelper
to backup the SharedPreferences
in my Android app. I have tested it in the emulator (Android 1.6 and 2.2) and on my own phone (Android 2.3.3) and it all works well. However, today I got a crash report in the Developer Console looking like this:
java.lang.RuntimeException: Unable to create BackupAgent com.xxx.yyy.MyBackupAgent: java.lang.ClassNotFoundException: com.xxx.yyy.MyBackupAgent in loader dalvik.system.PathClassLoader[/mnt/asec/com.xxx.yyy-2/pkg.apk]
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2114)
at android.app.ActivityThread.access$3200(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1138)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.m开发者_JS百科ain(Native Method)
Caused by: java.lang.ClassNotFoundException: com.xxx.yyy.MyBackupAgent in loader dalvik.system.PathClassLoader[/mnt/asec/com.xxx.yyy-2/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2064)
... 10 more
The backupAgent is declared in the application tag in the Manifest as:
android:backupAgent="com.xxx.yyy.MyBackupAgent"
Apparantly, the class MyBackupAgent
is present since I can build the .apk
and it runs just fine on several devices. So how can it be that it does not find the class here? One thing I notice in the message above is that the app seems to be installed in a path which have my package name AND an appended "-2" at the end. Can this cause the classloader to not see the class in my package since I specify the full package name and class in the android:backupAgent
, or is that part irrelevant? Can anybody understand what the reason can be that the class cannot be found?
Worth to mention is that my app can be installed on SD card.
Excuse me for replacing my real package name with com.xxx.yyy in the message above.
To me it seems like there's a duplicate package being installed on the device. If I were you, I'd test:
- Has the package name been inadvertently been changed.
- Have you tried to clean the project, uninstall the app from your test device, re-build and re-installed it?
I know these questions may seem like Captain Obvious to you but I can't tell you how many times these two things have saved me.
精彩评论