首页 > 解决方案 > TwitterSession 不能为空

问题描述

我已使用此代码撰写推文,但收到 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);

//OnClick按钮

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)

标签: androidtwitter

解决方案


推荐阅读