1

Facebook SDK Androidを使用してNullPointerExceptionFacebookにメッセージを投稿すると、エラーが発生します。がfacebook.authorizeCallback(requestCode, resultCode, data);呼び出されると、 でクラッシュしNullPointerExceptionます。

私のコード:

public void facebookShare(final String msg)
    {
        facebook = new Facebook(FACEBOOK_APPID);
        facebook.authorize(MainActivity.this,new String[] { FACEBOOK_PERMISSION },

                  new DialogListener() {
                       @Override
                       public void onComplete(Bundle values) {
                            try { 
                                Bundle parameters = new Bundle();
                                parameters.putString("message", msg);
                                String response = facebook.request("me/feed", parameters, "POST");
                                Log.d("fbproblem", "got response: " + response);
                                if (response == null || response.equals("") ||
                                    response.contains("error")) {
                                    Log.d("Login failed", "RETRY");
                                }
                                else {
                                    Log.d("fbproblem","Message posted to your facebook wall!");
                                    Toast.makeText(getApplicationContext(), "Message posted to your facebook wall!", Toast.LENGTH_LONG).show();                                 
                                    //facebook.logout(MainActivity.this);
                                }
                            }catch(Exception e) {
                                //finish();
                                Log.d("fbproblem", e.getMessage());
                            }
                           Log.d("fbproblem", "SUCCESS");
                           //finish();
                       }

                       @Override
                       public void onFacebookError(FacebookError error) {
                           Log.d("fbproblem", error.getMessage());
                           //finish();
                       }                               

                       @Override
                       public void onError(DialogError e) {
                           Log.d("fbproblem", e.getMessage());
                           //finish();
                       }

                       @Override
                       public void onCancel() {
                           Log.d("fbproblem", "");
                           //finish();
                       }
                  }
            );
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try
        {
            super.onActivityResult(requestCode, resultCode, data);
            facebook.authorizeCallback(requestCode, resultCode, data);
        }
        catch(Exception e)
        {
            Log.d("fbproblem", e.getMessage());
            Toast.makeText(getApplicationContext(), "Something goes wrong Try again Later!!", Toast.LENGTH_LONG).show();
        }
    }
4

1 に答える 1

0

アプリケーションの以下のコードを更新してください。

public void loginAndPostToWall() {
    facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
            new LoginDialogListener());
}
于 2012-06-08T12:44:12.050 に答える