当前位置: 首页 > 知识库问答 >
问题:

asynctask #2执行doinbackground()时出错

习海
2023-03-14

活动:

类 updateTwitterStatus extends AsyncTask {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Retos.this);
        pDialog.setMessage("Updating to twitter...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    protected String doInBackground(String... args) {
        Log.d("Tweet Text", "> " + args[0]);
        String status = args[0];
        try {
            ConfigurationBuilder builder = new ConfigurationBuilder();
            builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
            builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

            String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");

            String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

            AccessToken accessToken = new AccessToken(access_token, access_token_secret);
            Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

            twitter4j.Status response = twitter.updateStatus(status);

            Log.d("Status", "> " + response.getText());
        } catch (TwitterException e) {

            Log.d("Twitter Update Error", e.getMessage());
        }
        return null;
    }

    protected void onPostExecute(String file_url) {

        pDialog.dismiss();          
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(),
                        "Status tweeted successfully", Toast.LENGTH_SHORT).show();                  
                txtUpdate.setText("");
            }
        });
    }

}

这就是 LogCat

06-05 18:00:26.696: E/AndroidRuntime(1516): 致命异常: AsyncTask #2 06-05 18:00:26.696: E/AndroidRuntime(1516): java.lang.RuntimeException: 执行 doInBackground() 06-05 18:00:26.696: E/AndroidRuntime(151) 6): at android.os.AsyncTask$3.done(AsyncTask.java:299) 06-05 18:00:26.696: E/AndroidRuntime(1516): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 06-05 18:00:26.696: E/AndroidRuntime(1516): atjava.util.concurrent.FutureTask.setException(FutureTask.java:124) 06-05 18:00:26.696: E/AndroidRuntime(1516): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 06-05 18:00:26.696: E/AndroidRuntime(1516): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 06-05 18:00:26.696: E/AndroidRuntime(1516): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 06-05 18:00:26.696: E/AndroidRuntime(1516): atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 06-05 18:00:26.696: E/AndroidRuntime(1516): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 06-05 18:00:26.696: E /AndroidRuntime(1516): at java.lang.Thread.run(Thread.java:856) 06-05 18:00:26.696: E/AndroidRuntime(1516): Cause by: java.lang.NullPointerException 06-05 18:00:26.696: E/AndroidRuntime(1516): at com.example.prueba.Retos$updateTwitterStatus.doInBackground(Retos.java:145) 06-05 18:00:26.696: E/AndroidRuntime(1516): at com.example.prueba.Retos$updateTwitterStatus.doInBackground(Retos.java:1) 06-05 18:00:26.696: E/AndroidRuntime(1516): at android .os.AsyncTask$2.call(AsyncTask.java:287) 06-05 18:00:26.696: E/AndroidRuntime(1516): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 06-05 18:00:26.696: E/AndroidRuntime(1516): ...5更多

共有1个答案

左丘繁
2023-03-14

在Retos.java 145线附近寻找零点的可能性:

com.example.prueba.Retos$updateTwitterStatus.doInBackground(Retos.java:145)
 类似资料:
  • 我做了一个应用程序登录,一切都是正常的昨天,但今天android工作室给了我这个错误 {08-03 14:29:07.894 137 03-14015/Complete.Lyne.MyApplication E/AndroidRuntime:致命异常:AsyncTask#1进程:Complete.Lyne.MyApplication,PID:13703 java.lang.RuntimeExcep

  • 我在android设备上构建代码时出错了。这是错误报告 05-17 09:47:16.035 17982-18134/com . example . ckw . mapku E/Android runtime:致命异常:async task # 1 05-17 09:47:16.035 17982-18134/com . example . mapku E/Android runtime:Proc

  • 执行 时出错。 这是错误日志: 11-05 05:03:20.171:E/Android runtime(3171):致命异常:async task # 1 < br > 11-05 05:03:20.171:E/Android runtime(3171):Process:com . example . MySQL test,PID:3171 < br > 11-05 05:03:20.171:E

  • 我在android设备上构建代码时出错。这是错误报告 致命异常:AsyncTask#1进程:com。实例冈图,PID:1248爪哇。lang.RuntimeException:在android上执行doInBackground()时出错。操作系统。异步任务3美元。在java上完成(AsyncTask.java:304)。util。同时发生的未来任务。在java完成(FutureTask.java:

  • java.lang.RuntimeException:执行doInBackground()E/Android runtime(695)时出错:at Android . OS . async task $ 3 . done(async task . Java:200)E/Android runtime(695):at Java . util . concurrent . future task $

  • 问题内容: 我遵循了很多我认为确实正确的指南和其他问题,但是我有一个无法解决的错误。 反对这条线 我收到此错误 MainActivity.loadNotams类型必须实现继承的抽象方法AsyncTask.doInBackground(String …) 并反对这条线 我收到此错误: MainActivity.loadNotams类型的方法doInBackground(String)必须重写或实现一