Class extending Application throws ClassNotFoundException
Asked Answered
M

7

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

Millhon answered 16/4, 2013 at 21:7 Comment(3)
@blackbelt yes it is in my root/default folderMillhon
check with my explanation here #17253678 and also check with the issues that asked here.Hostility
application class is in library project ?Krick
L
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

Lardaceous answered 16/4, 2013 at 21:10 Comment(0)
C
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.

Conductive answered 9/7, 2013 at 20:7 Comment(0)
Y
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.

Yarber answered 6/7, 2013 at 0:43 Comment(0)
U
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

Unearned answered 6/7, 2013 at 1:59 Comment(2)
I do not use BOOT_COMPLETED or have an App WidgetMillhon
Those are just some examples of what can cause this. It can also happen if they remove the SD card.Unearned
L
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?

Lailaibach answered 6/7, 2013 at 2:5 Comment(1)
Fully qualified package name should not contain a dot at the beginningStuart
F
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.

Fascine answered 8/7, 2013 at 14:17 Comment(1)
Also goes for static initializers etcFascine
C
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.

Clarkia answered 10/7, 2013 at 3:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.