TwitterSession不能为null

时间:2019-02-11 06:11:30

标签: android twitter

我已经使用此代码编写了tweet,但收到了TweitterSession错误。在这里,我附上了日志,请帮助我解决此问题。

//在应用程序类中

TwitterConfig config = new TwitterConfig.Builder(this)
                    .logger(new DefaultLogger(Log.DEBUG))//enable logging when app is in debug mode
                    .twitterAuthConfig(new TwitterAuthConfig("ConsumerKey", "ConsumerSecret"))//pass the created app Consumer KEY and Secret also called API Key and Secret
                    .debug(true)//enable debug mode
                    .build();

            //finally initialize twitter with created configs

            Twitter.initialize(config);

//点击按钮

final TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
            final Intent intent = new ComposerActivity.Builder(MainActivity.this)
                    .session(session)
                    .text("Love where you work")
                    .hashtags("#twitter")
                    .createIntent();
            startActivity(intent);

日志::

TwitterSession must not be null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5461)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.IllegalArgumentException: TwitterSession must not be null
        at com.twitter.sdk.android.tweetcomposer.ComposerActivity$Builder.session(ComposerActivity.java:95)
        at com.example.inextrix.twittereazydemo.MainActivity.onCreate(MainActivity.java:51)
        at android.app.Activity.performCreate(Activity.java:6251)

0 个答案:

没有答案