9

I have a class that extends the application class and sometimes in my developer console I see an error saying ClassNotFoundException

java.lang.RuntimeException: Unable to instantiate application ecm2.android.ActiveStore: java.lang.ClassNotFoundException: ecm2.android.ActiveStore
at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4221)
at android.app.ActivityThread.access$1400(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: ecm2.android.ActiveStore
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:982)
at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
... 11 more

This is how I declare it in my manifest

<application
    android:name=".ActiveStore"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >

ActiveStore is just a class that holds an application context to start and cancel alrams so why would I get this error?

Update:

I am still seeing this error from time to time in my developer page even after putting a . infront of the class name. It seems to only happen on an update or new install

tyczj
  • 66,691
  • 50
  • 172
  • 271

7 Answers7

4

Probably because you're missing the dot in front of the class name (which helps to tell Dalvik that your class belongs to the package of your app)

.ActiveStore

But if in doubt, post both the whole Manifest file and your .java

DigCamara
  • 5,352
  • 4
  • 33
  • 45
1

In your manifest you should either have something like:

package="path.to.project.root"
...
<application 
    android:name=".MyApplication"

or as has been mentioned already

<application
    android:name="path.to.project.root.MyApplication"

Also make sure the constructor of your MyApplication class is public.

mpellegr
  • 2,818
  • 2
  • 19
  • 36
0

I'm also seeing this problem a lot and have no explanation. I've seen people saying that it can happen AFTER a crash. Supposedly, after a crash, the ClassLoader could be in a "bad" state and not be able to load classes. Basically this would mean that a prior bug is the real source of this problem. Sorry to be vague, please update if you find a more precise explanation.

BoD
  • 10,222
  • 6
  • 60
  • 57
0

If you have code that needs to run on startup (e.g. a BroadcastReceiver on BOOT_COMPLETED or an AppWidget), you can get this if the user has installed your app on an external SD card. At this point the SD card may not have been mounted yet, thus your Application class can't be loaded. You can solve this by setting the installation mode to internalOnly or in the case of the BroadcastReceiver wait for the broadcast of ACTION_MEDIA_MOUNTED. See android intent for sdcard ready

Community
  • 1
  • 1
keyboardr
  • 821
  • 1
  • 8
  • 20
0

Have you tried using the fully qualified package name to reference your class in your manifest?

.ActiveStore

would become

 com.myapp.package.ActiveStore

By any chance are you using ProGuard or anything similar to obfuscate your code?

Jade Byfield
  • 4,288
  • 5
  • 28
  • 40
0

I have experienced this before when I extended or implemented one of the classes/interfaces that was not available in a particular api level. It doesn't tell this in a proper way.

nickmartens1980
  • 1,583
  • 13
  • 23
0

I have seen this when there are verify errors for a different class the class in question depends on. Scroll back and see if there are any verification errors in the full logcat output.

If ecm2.android.ActiveStore depends on a class that fails verification, then you would get a class not found for ecm2.android.ActiveStore, not for the class ecm2.android.ActiveStore depends on.

Nick Palmer
  • 2,230
  • 1
  • 18
  • 30