调用方法时获取java.lang.NullPointerException

时间:2013-07-08 09:10:39

标签: java android exception twitter nullpointerexception

我正在将Twitter集成到Android应用程序中。当我尝试在代码中调用getOAuthAccessToken()方法时,它会抛出NullPointerException

// Parse the Intent data to get OAuth verifier.
public void getTwitterVerifier(final Intent intent) {

    Log.d(TAG, "Trying to get twitter verifier.");

    if (!isAlreadyLoggedInToTwitter()) {

        try {

            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {

                        Uri uri = intent.getData();

                        // OAuth verifier
                        final String verifier = uri
                                .getQueryParameter(URL_TWITTER_OAUTH_VERIFIER);

                        Log.d(TAG, "Request token : " + requestToken);
                        Log.d(TAG, "Verifier : " + verifier);

                        // Get the access token
                        AccessToken accessToken = twitter
                                .getOAuthAccessToken(requestToken, verifier); // THROWS EXCEPTION HERE.

                        // After getting access token and access token
                        // secret store them in shared preferences
                        Editor e = preferences.edit();
                        e.putString(TWITTER_OAUTH_TOKEN_KEY,
                                accessToken.getToken());
                        e.putString(TWITTER_OAUTH_SECRET_KEY,
                                accessToken.getTokenSecret());

                        // Set status to logged in
                        e.putBoolean(TWITTER_LOGGED_IN, true);
                        e.commit();

                        Log.d(TAG,
                                "Twitter OAuth Token"
                                        + accessToken.getToken());

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });

            thread.start();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
导致问题的行正上方的

Log语句显示非空值:

Request token : OAuthToken{token='6lneq6DKm0O9qg9rUJKuv4Coc6CA2GE0XwM4QPa3c', tokenSecret='p2ATEcqobFrHS2y6DyqSZkQqnxljKq8ObKGfEPcUL20', secretKeySpec=null}
Verifier : ZtTBbMAXTIBSlL3zX57WTeLraRg53mpgfrXVLUA4

我无法弄清楚问题所在。任何帮助将不胜感激。

0 个答案:

没有答案