简体   繁体   English

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

[英]Android ClassNotFoundException on BackupAgent (wrong package name)

I implemented a working BackupAgent a while ago but now the app crashes with the following LogCat. 不久前,我实现了一个工作正常的BackupAgent,但现在该应用因以下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. 事实是,它可以正常工作一段时间,并且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

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.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>

I've been searching Google with no solution for quite some time. 我搜索Google已有很长时间没有解决方案。 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. 请随时询问更多信息。

Replacing 更换

android:backupAgent="BackupAgent">

with

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

should fix your problem. 应该解决您的问题。 Just copy and paste. 只需复制并粘贴。

It seems that it was some error in Eclipse because after restarting the computer it works again. 看来这是Eclipse中的错误,因为在重新启动计算机后它又可以工作了。 Sometimes Eclipse produces inexplicable errors which are only solved by restarting Eclipse or even the whole computer. 有时Eclipse会产生无法解释的错误,这些错误只能通过重新启动Eclipse甚至整个计算机来解决。

Killing the "adb" process made the trick for me 杀死“ adb”过程对我来说是个诀窍

On Windows: 在Windows上:

  • go to Task Manager 去任务管理器
  • find "adb.exe" 找到“ adb.exe”
  • Select and click "End Task" 选择并单击“结束任务”

On Linux: 在Linux上:

  • find the process id, in a shell: ps -ef | 在shell中找到进程ID:ps -ef | grep adb grep adb
  • in a shell: kill -9 炮弹:杀死-9

In my case the issue was caused by ProGuard pruning the BackupAgent class. 就我而言,问题是由ProGuard修剪BackupAgent类引起的。 Adding a rule below to the proguard-rules.pro resolves the issue: 在proguard-rules.pro中添加以下规则可解决此问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM