asynctask#2执行doinbackground()时发生错误

时间:2014-06-05 18:28:40

标签: android-asynctask

的活动:

class updateTwitterStatus扩展了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(1516):在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):at java.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):在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230) 06-05 18:00:26.696:E / AndroidRuntime(1516):at java.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):引起: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):在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 more

1 个答案:

答案 0 :(得分:1)

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

com.example.prueba.Retos$updateTwitterStatus.doInBackground(Retos.java:145)