要的Andr​​oid无法实例化应用抛出java.lang.ClassNotFoundException: [英] Android to Unable to instantiate Application java.lang.ClassNotFoundException:

查看:155
本文介绍了要的Andr​​oid无法实例化应用抛出java.lang.ClassNotFoundException:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的应用程序,它是主机上的Andr​​oid市场。有时(每月一次)我得到了一个崩溃报告:

I am working on application which is host on android market. Sometimes (once a month ) I got a crash report:

无法实例化应用程序抛出java.lang.ClassNotFoundException

Unable to instantiate application java.lang.ClassNotFoundException

应用软件下载是10,000-50,000之间。我不知道为什么这个异常提高在某些设备上不是所有的(我测试了3种不同的设备与功放,我不能在我结束重新产生的话)。

App downloads are between 10,000-50,000. I don't know why this exceptions raise on some devices not all ( I tested it on 3 different devices & I couldn't re-produce it at my end).

我读了不同的Andr​​oid论坛上关于这个问题的文章/建议,但我并没有解决它取得成功。有没有人遇到类似的问题和放大器;建议我该怎么办?

I read articles/suggestions on different android forums regarding the issue but I didn't succeed in solving it. Does anyone face similar issue & suggest me what should I do?

注意: 我伸出像这样的应用程序类

Note: I am extending application class like this

public class MyApplication extends Application {

}

我在这样的manifest.xml的注册它

I register it in the manifest.xml like this

<application android:icon="@drawable/app_icon"
    android:label="@string/my_app_name" android:name="MyApplication">

堆栈跟踪:

java.lang.RuntimeException: Unable to instantiate application  com.xyz.MyApplication      java.lang.ClassNotFoundException: com.xyz.MyApplication in loader dalvik.system.PathClassLoader[/mnt/asec/com.xyz-1/pkg.apk]
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:650)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4238)
at android.app.ActivityThread.access$3000(ActivityThread.java:126)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2076)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.xyz.MyApplication in loader dalvik.system.PathClassLoader[/mnt/asec/com.xyz-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newApplication(Instrumentation.java:942)
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:645)

我不知道在某些设备上,为什么应用程序崩溃不是全部。

I don't know why application crash on some devices not all.

推荐答案

我认为这个问题是getApplication()我都用在10个不同的地方。所以,我已经使用Singleton模式来解决这个问题。

I think the problem is with getApplication() which I have used in 10 different place. So I have used singleton pattern to solve this.

public class MyApplication extends Application {
    private static MyApplication me;

    @Override
    public void onCreate() {        
        super.onCreate();
        me = this ;

    }
    public static MyApplication getInstance() {
         return me;
    }
}

现在我已经使用getApplication()这样的

Now I have used getApplication() like this

     MyApplication application = MyApplication.getInstance();

的insted的

insted of

     MyApplication application = (MyApplication) getApplication();

我已经上传了市场和放大器的固定版本;现在正等待如果没有了这种崩溃。如果一切顺利完美的(如果在2周内没有更多的崩溃),那么我会关闭的问题。在同时任何人有更好的想法或知道解决的办法,请分享。
谢谢,

I have uploaded the fixed version on the market & now waiting if there is anymore this kind of crash. If everything goes perfect ( if no more crash in 2 weeks) then I will close the question. In meanwhile anyone has better idea or know the solution , please share it.
Thanks,

这篇关于要的Andr​​oid无法实例化应用抛出java.lang.ClassNotFoundException:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆