不久前我实现了一个有效的 BackupAgent,但现在应用程序因以下 LogCat 而崩溃。问题是,它在一段时间内运行良好,BackupAgent.java 实际上位于 maturaarbeit.nicola_pfister.marks.backup 包中,而不是 LogCat 所说的包中。
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
因为包似乎是我一直在 Manifest.xml 中寻找错误的错误,但对我来说似乎没问题:
<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>
我一直在谷歌搜索很长一段时间都没有解决方案。即使从构建路径中排除该类也不起作用。备份代理永远不会从任何让我更加恼火的课程中调用。
感谢您的时间和帮助。不要犹豫,询问更多信息。