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

3

7 Answers 7

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

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.

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

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

2
  • I do not use BOOT_COMPLETED or have an App Widget
    – tyczj
    Jul 6, 2013 at 2:35
  • Those are just some examples of what can cause this. It can also happen if they remove the SD card.
    – keyboardr
    Jul 6, 2013 at 2:53
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.

1
  • Also goes for static initializers etc Jul 9, 2013 at 6:46
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.

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?

1
  • Fully qualified package name should not contain a dot at the beginning
    – Gomino
    Jul 10, 2013 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.