8

This exception is reported 10/week, I tried to find solution but failed. I'm a little frustrated with this sort of exception, and searched all related posts. (P.S. I noticed that full name (android:name="com.example.AcraApplication") throw more exceptions than short one(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

EDIT: I noticed that when I reinstall&open using ctrl+F11 in eclipse without clicking its icon, it occurs more frequently.

ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
thecr0w
  • 2,148
  • 4
  • 33
  • 59
  • 1
    This can be caused by an exception initializing the class. It could be the class fails to create due to some sort of static variables. Try cleaning your project and building it again. If you are loading any data at application startup ensure that it is always loaded or load it lazily. –  Feb 27 '14 at 02:04
  • 3
    Looks like the system has trouble opening your application dex file `java.io.IOException: unable to open DEX file`, this is before any of your classes are loaded, so it doesn't have anything to do with how you define your application class in the Manifest. –  Feb 27 '14 at 02:25
  • @RazsApps, load it lazily, I 'll have a try. thank you. – thecr0w Feb 28 '14 at 09:20

2 Answers2

11

Have you declared the package name at the top of your class files?

It should have a package declared at the top of each class file like so:

package com.example;

import ...

public class AcraApplication extends Application {
    ...
}

All of your class files with that package declaration should be in the same directory, src/com/example.

You must also declare your package in your AndroidManifest.xml file as well as all subclasses as <activity ... />

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

    <application
        ... >
        <activity
            android:name=".AcraApplication"
            ... >
        </activity>
    </application>
</manifest>
Adam
  • 2,532
  • 1
  • 24
  • 34
-2

I also had the same error. Solved it by adding below permission in manifest file.

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

Hope this helps. :)

Nikolay Mihaylov
  • 3,868
  • 8
  • 27
  • 32