BackupAgent上的Android ClassNotFoundException(错误的包名称)

时间:2013-05-05 14:53:39

标签: android backup classnotfoundexception agent

我刚刚实现了一个有效的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 个答案:

答案 0 :(得分:0)

更换

android:backupAgent="BackupAgent">

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

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

答案 1 :(得分:0)

似乎在Eclipse中出现了一些错误,因为重新启动计算机后它再次运行。有时Eclipse会产生莫名其妙的错误,只有重新启动Eclipse甚至整个计算机才能解决这些错误。

答案 2 :(得分:0)

杀死&#34; adb&#34;过程为我做了伎俩

在Windows上:

  • 转到任务管理器
  • 找到&#34; adb.exe&#34;
  • 选择并点击&#34;结束任务&#34;

在Linux上:

  • 在shell中找到进程ID:ps -ef | grep adb
  • 在一个shell中:kill -9

答案 3 :(得分:0)

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

-keep class com.myapp.backup.BackupAgent { *; }