2016-05-09 9 views
0

Ich habe versucht, klicken Sie auf programmatische Weise, aber App immer Absturz.twitterLoginButton.performClick(); funktioniert nicht in android

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(); 

Gegeben unten Fehler. Manuelle Tastenklicks adaequat, kann nicht figure_out das Problem ...

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) 

Antwort

0

Anruf twitterLoginButton.performClick();, nachdem Sie Ihren Rückruf gesetzt

+0

Ja in gleicher Weise nur ich genannt. Bitte gehen Sie den gebuchten Code einmal durch. –

+0

Der gepostete Code ruft performClick auf, bevor der Rückruf festgelegt wird. 'twitterLoginButton.setCallback' sollte das erste sein, was Sie anrufen, nachdem Sie twitterLoginButton –

+0

Thanks, Its Worked gesetzt haben –

Verwandte Themen