Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class extending Application throws ClassNotFoundException

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

like image 202
tyczj Avatar asked Apr 16 '13 21:04

tyczj


People also ask

Which method throws the ClassNotFoundException?

Class ClassNotFoundException. Thrown when an application tries to load in a class through its string name using: The forName method in class Class . The findSystemClass method in class ClassLoader .

What causes ClassNotFoundException?

ClassNotFoundException is a checked exception which occurs when an application tries to load a class through its fully-qualified name and can not find its definition on the classpath. This occurs mainly when trying to load classes using Class. forName(), ClassLoader. loadClass() or ClassLoader.

How do I fix Java Lang ClassNotFoundException in eclipse?

click on project->properties->Java build path->Source and check each src folder is still valid exist or recently removed. Correct any missing path or incorrect path and rebuild and run the test. It will fix the problem.


1 Answers

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

like image 183
DigCamara Avatar answered Oct 13 '22 11:10

DigCamara