Question

I implemented a working BackupAgent a while ago but now the app crashes with the following LogCat. The thing is, it worked fine for some time and the BackupAgent.java is actually in the maturaarbeit.nicola_pfister.marks.backup package and not in the package the LogCat says.

05-05 14:26:52.516: E/ActivityThread(1553): Agent threw during creation: java.lang.ClassNotFoundException: maturaarbeit.nicola_pfister.marks.BackupAgent
05-05 14:27:08.797: D/AndroidRuntime(1553): Shutting down VM
05-05 14:27:08.797: W/dalvikvm(1553): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
05-05 14:27:08.906: E/AndroidRuntime(1553): FATAL EXCEPTION: main
05-05 14:27:08.906: E/AndroidRuntime(1553): java.lang.RuntimeException: Unable to create BackupAgent maturaarbeit.nicola_pfister.marks.BackupAgent: java.lang.ClassNotFoundException: maturaarbeit.nicola_pfister.marks.BackupAgent
05-05 14:27:08.906: E/AndroidRuntime(1553):     at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2309)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at android.app.ActivityThread.access$2300(ActivityThread.java:130)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1336)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at android.os.Looper.loop(Looper.java:137)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at android.app.ActivityThread.main(ActivityThread.java:4745)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at java.lang.reflect.Method.invokeNative(Native Method)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at java.lang.reflect.Method.invoke(Method.java:511)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at dalvik.system.NativeStart.main(Native Method)
05-05 14:27:08.906: E/AndroidRuntime(1553): Caused by: java.lang.ClassNotFoundException: maturaarbeit.nicola_pfister.marks.BackupAgent
05-05 14:27:08.906: E/AndroidRuntime(1553):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-05 14:27:08.906: E/AndroidRuntime(1553):     at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2280)
05-05 14:27:08.906: E/AndroidRuntime(1553):     ... 10 more
05-05 14:32:42.866: E/Trace(1570): error opening trace file: No such file or directory (2)
05-05 14:32:42.936: E/ActivityThread(1570): Agent threw during creation: java.lang.ClassNotFoundException: backup.BackupAgent
05-05 14:32:42.936: D/AndroidRuntime(1570): Shutting down VM
05-05 14:32:42.936: W/dalvikvm(1570): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
05-05 14:32:42.956: E/AndroidRuntime(1570): FATAL EXCEPTION: main
05-05 14:32:42.956: E/AndroidRuntime(1570): java.lang.RuntimeException: Unable to create BackupAgent backup.BackupAgent: java.lang.ClassNotFoundException: backup.BackupAgent
05-05 14:32:42.956: E/AndroidRuntime(1570):     at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2309)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at android.app.ActivityThread.access$2300(ActivityThread.java:130)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1336)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at android.os.Looper.loop(Looper.java:137)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at android.app.ActivityThread.main(ActivityThread.java:4745)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at java.lang.reflect.Method.invokeNative(Native Method)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at java.lang.reflect.Method.invoke(Method.java:511)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at dalvik.system.NativeStart.main(Native Method)
05-05 14:32:42.956: E/AndroidRuntime(1570): Caused by: java.lang.ClassNotFoundException: backup.BackupAgent
05-05 14:32:42.956: E/AndroidRuntime(1570):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-05 14:32:42.956: E/AndroidRuntime(1570):     at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2280)
05-05 14:32:42.956: E/AndroidRuntime(1570):     ... 10 more

Because the package seems to be the error I've been looking for the error in the Manifest.xml but it seems to be ok to me:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="maturaarbeit.nicola_pfister.marks"
    android:versionCode="14"
    android:versionName="1.4" android:installLocation="auto">
    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.android.vending.BILLING"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:logo="@drawable/ic_action_marks"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo.Light"
        android:allowBackup="true"
        android:backupAgent="BackupAgent">

        <activity
            android:name=".Main" 
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="portrait"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name="Marks"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="portrait"
            >
        </activity>
        <activity android:name=".billing.Donate"></activity>
        <meta-data android:name="com.google.android.backup.api_key" android:value="[censored]" />

    </application>

</manifest>

I've been searching Google with no solution for quite some time. Even excluding the class from the build path didn't work. The backup agent is never called from any class which irritates me even more.

Thanks for your time and help. Don't hesitate asking for more information.

Was it helpful?

Solution 2

It seems that it was some error in Eclipse because after restarting the computer it works again. Sometimes Eclipse produces inexplicable errors which are only solved by restarting Eclipse or even the whole computer.

OTHER TIPS

Replacing

android:backupAgent="BackupAgent">

with

android:backupAgent="maturaarbeit.nicola_pfister.marks.backup.BackupAgent">

should fix your problem. Just copy and paste.

Killing the "adb" process made the trick for me

On Windows:

  • go to Task Manager
  • find "adb.exe"
  • Select and click "End Task"

On Linux:

  • find the process id, in a shell: ps -ef | grep adb
  • in a shell: kill -9

In my case the issue was caused by ProGuard pruning the BackupAgent class. Adding a rule below to the proguard-rules.pro resolves the issue:

-keep class com.myapp.backup.BackupAgent { *; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top