简体   繁体   English

无法实例化扩展应用程序类的应用程序错误

[英]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. 我还没有通过测试用的android手机看到它,但是我通过Google开发者控制台获得了它的迷恋。

[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'. 我怀疑这可能是由于外部SD卡问题或“公共构造函数”引起的。 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. 因为即使我也不知道如何重现这种情况,所以我不确定这是由于SD卡还是公共构造函数造成的。

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. 谢谢。

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 . 要进一步阅读,如何扩展Application类,请在此处阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM