• oPhone的手机不支持AsyncTask.execute(new Runnable() {这样的写法


    在我的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);

     

  • 相关阅读:
    MS面试归来:)
    准备出发到成都
    线程的同步机制(zz)
    Windows Vista(zz)
    这几天上海热晕了
    微软官方:Vista硬件要求指南(zz)
    有趣的递归缩写(Recursive acronym)
    《三国志》生僻人名读法集(zz)
    Git bash常用命令
    各大输入法分类词库内部格式的简单比较
  • 原文地址:https://www.cnblogs.com/ghj1976/p/3077360.html
Copyright © 2020-2023  润新知