3
votes

Activity:

class 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("");
            }
        });
    }

}

And this is the LogCat

06-05 18:00:26.696: E/AndroidRuntime(1516): FATAL EXCEPTION: AsyncTask #2 06-05 18:00:26.696: E/AndroidRuntime(1516): java.lang.RuntimeException: An error occured while executing doInBackground() 06-05 18:00:26.696: E/AndroidRuntime(1516): 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): 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): at 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): Caused 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 more

1

1 Answers

1
votes

Look for a null point possibility at Retos.java near line 145:

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