Android“ClassNotFoundException”有时会发生

时间:2012-09-24 00:51:05

标签: android

我最近向市场发布了我的应用,我的应用在为少数用户加载时崩溃了。我无法在手机或模拟器上重现错误。这是堆栈..

应用程序崩溃的原因是什么?有没有人遇到过这个问题?

java.lang.RuntimeException: Unable to instantiate application
xyz.android.MyApplication: java.lang.ClassNotFoundException: xyz.android.MyApplication in loader dalvik.system.PathClassLoader[/data/app/rageup.android.official-2.apk]
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:671)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4322)
at android.app.ActivityThread.access$3200(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2155)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
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:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: xyz.android.MyApplication in loader     dalvik.system.PathClassLoader[/data/app/xyz.android.official-2.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:666)
... 11 more

以下是我的清单文件的片段

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.android.official"
android:versionCode="AAA"
android:versionName="AAA" >

<uses-sdk android:minSdkVersion="7" />
<application
    android:name="xyz.android.MyApplication"
    android:icon="@drawable/myicon"
    android:label="@string/app_name">

这是我的MyApplication类。

public class MyApplication extends Application 
{ 

public int someVar = 555;
private static MyApplication me;

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

public void setSomeVar(int someVar)
{       
    this.someVar = someVar;
}

public int getSomeVar()
{
    return someVar;
}

public static MyApplication getInstance() {
     return me;
}

}

1 个答案:

答案 0 :(得分:0)

这主要导致了目标构建的改变。有人说您需要将库文件夹从lib更改为libs,其他人说您应该在Manifest.xml中编写.MyApplication

来源:java.lang.ClassNotFoundException on working app