在我的oPhone手机上,执行一个APP,总是报错。
报错的代码如下在:
AsyncTask.execute(new Runnable() {
@Override
public void run() {
//一些后台逻辑代码
}
});
错误信息: java.lang.NoSuchMethodError: android.os.AsyncTask.execute
详细的错误信息如下:
05-14 10:17:53.468: E/AndroidRuntime(2139): FATAL EXCEPTION: main
05-14 10:17:53.468: E/AndroidRuntime(2139): java.lang.NoSuchMethodError: android.os.AsyncTask.execute
05-14 10:17:53.468: E/AndroidRuntime(2139): at cn.inpads.customercare.ui.activity.SplashActivity.onCreate(SplashActivity.java:40)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1650)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1702)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.app.ActivityThread.access$1500(ActivityThread.java:119)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:959)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.os.Looper.loop(Looper.java:130)
05-14 10:17:53.468: E/AndroidRuntime(2139): at android.app.ActivityThread.main(ActivityThread.java:3796)
05-14 10:17:53.468: E/AndroidRuntime(2139): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 10:17:53.468: E/AndroidRuntime(2139): at java.lang.reflect.Method.invoke(Method.java:507)
05-14 10:17:53.468: E/AndroidRuntime(2139): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-14 10:17:53.468: E/AndroidRuntime(2139): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-14 10:17:53.468: E/AndroidRuntime(2139): at dalvik.system.NativeStart.main(Native Method)
如果把这里的代码修改成下面方式就不会报错了:
new AsyncTask<Integer, Integer, String>() {
@Override
protected String doInBackground(Integer... params) {
// 一些后台线程逻辑代码
return null;
}
protected void onPostExecute(String result) {
};
}.execute(1000);