Android应用程序ClassNotFoundException,无法实例化应用程序

时间:2014-02-27 01:58:41

标签: android classnotfoundexception

这个例外报告每周10次,我试图找到解决方案但失败了。我对这种异常感到有些沮丧,并搜索了所有相关帖子。 (P.S.我注意到全名(android:name =“com.example.AcraApplication”)抛出的异常多于短篇(android:name =“。AcraApplication”)。)

public class AcraApplication extends Application {
public void onCreate() {
        ACRA.init(this);
        super.onCreate();
    }


<application
        android:name=".AcraApplication"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name" >

logcat的:

java.lang.RuntimeException: Unable to instantiate application com.example.AcraApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.AcraApplication" on path: DexPathList[[zip file "/mnt/asec/com.example-2/pkg.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4554)
at android.app.ActivityThread.access$1600(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1325)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.AcraApplication" on path: DexPathList[[zip file "/mnt/asec/com.example-2/pkg.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:993)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
Suppressed: java.io.IOException: unable to open DEX file
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:296)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexFile.<init>(DexFile.java:59)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:263)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
at dalvik.system.DexPathList.<init>(DexPathList.java:112)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:58)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:57)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:326)
at android.app.LoadedApk.makeApplication(LoadedApk.java:508)
... 11 more

编辑:我注意到当我在eclipse中重新安装并使用ctrl + F11打开而不点击它的图标时,会更频繁地发生。

2 个答案:

答案 0 :(得分:9)

您是否已将包名称声明在类文件的顶部?

它应该在每个类文件的顶部声明一个包,如下所示:

package com.example;

import ...

public class AcraApplication extends Application {
    ...
}

具有该包声明的所有类文件应位于同一目录src/com/example

您还必须在AndroidManifest.xml文件以及所有子类中声明您的包<activity ... />

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example"
    ... >

    <application
        ... >
        <activity
            android:name=".AcraApplication"
            ... >
        </activity>
    </application>
</manifest>

答案 1 :(得分:-2)

我也有同样的错误。 通过在清单文件中添加以下权限来解决它。

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

希望这会有所帮助。 :)