SY Kwon
SY Kwon

Reputation: 159

Unable to instantiate application error which extends Application class

The below error occurs sometimes for some users. I haven't seen it through android phones which I have for testing, but I got this crush via Google developer console.

[Error]
java.lang.RuntimeException: Unable to instantiate application com.***.***.MyApplication: java.lang.ClassNotFoundException: com.***.***.MyApplication
at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4253)
at android.app.ActivityThread.access$1400(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1301)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4950)
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:997)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.***.***.MyApplication
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

[MyApplication.java]
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
            ...
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    ...

}

[manifest.xml]
...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
...
<application
        android:name="com.***.***.MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

I've tried to find out to solve this problem. I doubt it might be due to external SD card problem or 'public constructor'. Because even I do not know how to reenact the situation, I can't be sure whether this is due to SD card or public constructor stuff.

I'm sure there's somebody who got this error and already know how to solve this. Thus, please help me know what's wrong and how I can fix it. Thanks.

Upvotes: 1

Views: 1164

Answers (1)

Waqar Ahmed
Waqar Ahmed

Reputation: 5068

add your class name in your manifest file. hope this solve your problem

<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:name=".MyApplication">

  ........

for further reading , how to extends Application class, read here.

Upvotes: 1

Related Questions