0

不久前我实现了一个有效的 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>

我一直在谷歌搜索很长一段时间都没有解决方案。即使从构建路径中排除该类也不起作用。备份代理永远不会从任何让我更加恼火的课程中调用。

感谢您的时间和帮助。不要犹豫,询问更多信息。

4

4 回答 4

0

更换

android:backupAgent="BackupAgent">

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

应该解决你的问题。只需复制和粘贴。

于 2013-05-05T17:01:02.327 回答
0

这似乎是 Eclipse 中的一些错误,因为重新启动计算机后它又可以工作了。有时 Eclipse 会产生莫名其妙的错误,只有重新启动 Eclipse 甚至整个计算机才能解决。

于 2013-05-05T17:36:54.520 回答
0

杀死“adb”进程对我来说是个窍门

在 Windows 上:

  • 进入任务管理器
  • 找到“adb.exe”
  • 选择并单击“结束任务”

在 Linux 上:

  • 在 shell 中查找进程 ID:ps -ef | grep 亚行
  • 在外壳中:杀死 -9
于 2014-07-10T16:15:48.637 回答
0

就我而言,问题是由 ProGuard 修剪 BackupAgent 类引起的。将以下规则添加到 proguard-rules.pro 可解决该问题:

-keep class com.myapp.backup.BackupAgent { *; }
于 2016-07-21T17:58:33.083 回答