twitterLoginButton.performClick();不在android工作

时间:2016-05-09 10:48:20

标签: android twitter-fabric android-twitter

我尝试按点编程方式执行,但应用程序每次都会崩溃。

twitterLoginButton = (TwitterLoginButton) findViewById(R.id.twitterLogin);
    twitterLoginButton.performClick();
    twitterLoginButton.setPressed(true);
    twitterLoginButton.invalidate();
    //Adding callback to the button
    twitterLoginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            //If login succeeds passing the Calling the login method and passing Result object
            twitterLogin(result);
        }
        @Override
        public void failure(TwitterException exception) {
            //If failure occurs while login handle it here
            Log.d("TwitterKit", "Login with Twitter failure", exception);
        }
    });
    twitterLoginButton.setPressed(false);
    twitterLoginButton.invalidate();

给出以下错误。手动按钮点击工作正常,无法解决问题...

 FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.tettares.whatdoieat/com.tettares.whatdoieat.login.FBOrTwitterLoginActivity}: java.lang.IllegalArgumentException: Callback must not be null 
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
 at android.app.ActivityThread.access$800(ActivityThread.java:155) 
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) 
 at android.os.Handler.dispatchMessage(Handler.java:102)at android.os.Looper.loop(Looper.java:135)
 at android.app.ActivityThread.main(ActivityThread.java:5343) at java.lang.reflect.Method.invoke(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
 Caused by: java.lang.IllegalArgumentException: Callback must not be null. at 
  com.twitter.sdk.android.core.identity.TwitterAuthClient.authorize(TwitterAuthClient.java:95)at 
  com.twitter.sdk.android.core.identity.TwitterLoginButton$LoginClickListener.onClick(TwitterLoginButton.java:161) 
  at android.view.View.performClick(View.java:4785)

1 个答案:

答案 0 :(得分:0)

设置回拨后调用twitterLoginButton.performClick();