2016-03-02 87 views
0

在我的應用Twitter的整合引發以下非法參數異常java.lang.IllegalArgumentException異常:TwitterSession不能爲空

TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET); 
Fabric.with(this, new Twitter(authConfig), new Crashlytics()); 
TwitterSession twitterSession = Twitter.getSessionManager().getActiveSession(); 
Intent intent = new ComposerActivity.Builder(MainActivity.this) 
        .session(twitterSession) 
        .darkTheme()      
        .createIntent(); 
startActivity(intent); 

的logcat:

03-02 14:21:04.183 29087-29087/com.example.admin.twitterintegration E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.example.admin.twitterintegration, PID: 29087 
java.lang.IllegalArgumentException: TwitterSession must not be null 
at com.twitter.sdk.android.tweetcomposer.ComposerActivity$Builder.session(ComposerActivity.java:79) 
at com.example.admin.twitterintegration.MainActivity$3.onClick(MainActivity.java:105) 
at android.view.View.performClick(View.java:4640) 
at android.view.View$PerformClick.run(View.java:19425) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5593) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
at dalvik.system.NativeStart.main(Native Method) 

感謝您的幫助。

回答

0

在登錄按鈕

TwitterLoginButton loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button); 
    Callback twitterCallback = new Callback<TwitterSession>() { 
     @Override 
     public void success(Result<TwitterSession> result) { 
      // Do something with result, which provides a TwitterSession for making API calls 
     } 

     @Override 
     public void failure(TwitterException exception) { 
      // Do something on failure 
     } 
    }; 
    loginButton.setCallback(twitterCallback); 

添加回調onActivityResult

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
    super.onActivityResult(requestCode, resultCode, data); 

    // Pass the activity result to the login button. 
    loginButton.onActivityResult(requestCode, resultCode, data); 
    } 

更多細節請參考Authentication Log in with Twitter

+0

它拋出一個Twitter會話異常無關,與回調和登錄按鈕。如果我不正確引導我。 – prasanthMurugan

+0

檢查更新答案 – sasikumar

+0

我沒有使用默認的twitter按鈕和回調方法。我使用[doc鏈接](https://docs.fabric.io/android/twitter/compose-tweets.html)創建一個twitter會話但它會拋出上述異常 – prasanthMurugan

相關問題