获取 NoClassDefFoundError:android.os.AsyncTask [英] Getting NoClassDefFoundError: android.os.AsyncTask
问题描述
这个问题一直困扰我一段时间,我找不到满意的解决方案.
This problem has been bothering me for a bit and I cannot find a satisfactory solution.
多次(并非总是)在 Android 模拟器上创建特定对象时,我收到 NoClassDefFoundError: android.os.AsynchTask.
Many times (not always) in the creation of a specific object on the Android emulator I get NoClassDefFoundError: android.os.AsynchTask.
我尝试了很多方法,多次删除和重新添加外部库,擦除模拟器,重新启动 IntelliJ(工作过一次,但出现相同的错误.)此时我想做的就是构建最准系统的 AsyncTask我仍然收到错误.
I have tried many approaches removing and re-adding external libraries multiple times, wiping the emulator, restarting IntelliJ (worked once but then got the same error.) At this point all I am trying to do is construct the most barebones AsyncTask and I still get the error.
这里是整个错误信息:
08-06 16:24:43.546: ERROR/AndroidRuntime(331): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.os.AsyncTask
at com.myapp.activity.StatisticsActivity.onCreate(StatisticsActivity.java:79)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
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)
模拟器运行 2.2,我的 minSDK 是 8.这是违规代码:
The emulator runs 2.2, my minSDK is 8. Here is the offending code:
public class StatisticsActivity extends TabActivity implements AsynchDataDisplay{
...
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.statistics);
StatisticsProvider sp = new StatisticsProvider();
...
}
}
StatisticsProvider 对象是:
And the StatisticsProvider object is:
private class StatisticsProvider extends AsyncTask{
@Override
protected Object doInBackground(Object... objects) {
return null;
}
}
推荐答案
好的,看起来是 Google play 服务版本之一的问题.请参阅 https://code.google.com/p/android/issues/详细信息?id=81083
OK, looks like it is a problem with one of the versions of Google play Services. See https://code.google.com/p/android/issues/detail?id=81083
看起来解决方法可能是添加:
Looks like a work around might be to add:
try {
Class.forName("android.os.AsyncTask");
}
catch(Throwable ignore) {
// ignored
}
进入你的Application#onCreate()
如果您还没有 Application 类,则创建一个从 android.app.Application
和
If you don't already have a Application class then create a class that extends from android.app.Application
and
- 将上面的代码添加到它的
#onCreate()
- 在 AndroidManifest 的应用程序元素中添加对应用程序类的引用.
<application android:icon="@drawable/icon_game_launcher"
android:label="@string/app_name"
android:name="au.com.mycompany.myapp.MyApplication">
这篇关于获取 NoClassDefFoundError:android.os.AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!