Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8333903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:10:31+00:00 2026-06-09T03:10:31+00:00

I have an application using facebook post. I am using a force login mFacebook.authorize(this,

  • 0

I have an application using facebook post. I am using a force login

   mFacebook.authorize(this, PERMS, Facebook.FORCE_DIALOG_AUTH,  new LoginDialogListener());

instead of

  mFacebook.authorize(this, PERMS, new LoginDialogListener());

because with the standard authorize method I couldn’t post to facebook. Now the post works, but I get this error:

08-06 20:35:52.814: W/System.err(682): java.lang.NullPointerException
08-06 20:35:52.824: W/System.err(682):  at com.b2creativedesigns.b2lovecalculator.FacebookActivity$IDRequestListener$1.run(FacebookActivity.java:147)
08-06 20:35:52.824: W/System.err(682):  at android.os.Handler.handleCallback(Handler.java:587)
08-06 20:35:52.824: W/System.err(682):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-06 20:35:52.824: W/System.err(682):  at android.os.Looper.loop(Looper.java:123)
08-06 20:35:52.824: W/System.err(682):  at android.app.ActivityThread.main(ActivityThread.java:4363)
08-06 20:35:52.824: W/System.err(682):  at java.lang.reflect.Method.invokeNative(Native Method)
08-06 20:35:52.824: W/System.err(682):  at java.lang.reflect.Method.invoke(Method.java:521)
08-06 20:35:52.824: W/System.err(682):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-06 20:35:52.824: W/System.err(682):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-06 20:35:52.824: W/System.err(682):  at dalvik.system.NativeStart.main(Native Method)

However, despite the error, I get no visible error (force close) in the app:

This is the facebook activity:

public abstract class FacebookActivity extends Activity {
    public static final String TAG = "FACEBOOK";
    private Facebook mFacebook;
    public static final String APP_ID = "blablabla"; //the API Key for your Facebook APPs
    private AsyncFacebookRunner mAsyncRunner;
    private static final String[] PERMS = new String[] { "publish_stream" };
    private SharedPreferences sharedPrefs;
    private Context mContext;

    private TextView username;
    private ProgressBar pb;

    public void setConnection() {
            mContext = this;
            mFacebook = new Facebook(APP_ID);
            mAsyncRunner = new AsyncFacebookRunner(mFacebook);
    }

    public void getID(TextView txtUserName, ProgressBar progbar) {
            username = txtUserName;
            pb = progbar;
            if (isSession()) {
                    Log.d(TAG, "sessionValid");
                    mAsyncRunner.request("me", new IDRequestListener());
            } else {
                    // no logged in, so relogin
                    Log.d(TAG, "sessionNOTValid, relogin");
                    //mFacebook.authorize(this, PERMS, new LoginDialogListener());
                    mFacebook.authorize(this, PERMS, Facebook.FORCE_DIALOG_AUTH,  
                            new LoginDialogListener());
            }
   }

    public void logout() {
        mContext = this;

        try {

           mFacebook = new Facebook(APP_ID);
           mFacebook.logout(mContext);
           //mFacebook.authorize(this, PERMS, -1, new LoginDialogListener());

          Log.d(TAG, "ssucesfull logout");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

    public boolean isSession() {
            sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
            String access_token = sharedPrefs.getString("access_token", "x");
            Long expires = sharedPrefs.getLong("access_expires", -1);
            Log.d(TAG, access_token);

            if (access_token != null && expires != -1) {
                    mFacebook.setAccessToken(access_token);
                    mFacebook.setAccessExpires(expires);
            }
            return mFacebook.isSessionValid();
    }

    private class LoginDialogListener implements DialogListener {

            @Override
            public void onComplete(Bundle values) {
                    Log.d(TAG, "LoginONComplete");
                    String token = mFacebook.getAccessToken();
                    long token_expires = mFacebook.getAccessExpires();
                    Log.d(TAG, "AccessToken: " + token);
                    Log.d(TAG, "AccessExpires: " + token_expires);
                    sharedPrefs = PreferenceManager
                                    .getDefaultSharedPreferences(mContext);
                    sharedPrefs.edit().putLong("access_expires", token_expires)
                                    .commit();
                    sharedPrefs.edit().putString("access_token", token).commit();
                    mAsyncRunner.request("me", new IDRequestListener());
            }

            @Override
            public void onFacebookError(FacebookError e) {
                    Log.d(TAG, "FacebookError: " + e.getMessage());
            }

            @Override
            public void onError(DialogError e) {
                    Log.d(TAG, "Error: " + e.getMessage());
            }

            @Override
            public void onCancel() {
                    Log.d(TAG, "OnCancel");
            }
    }

    private class IDRequestListener implements RequestListener {

            @Override
            public void onComplete(String response, Object state) {
                    try {
                            Log.d(TAG, "IDRequestONComplete");
                            Log.d(TAG, "Response: " + response.toString());
                            JSONObject json = Util.parseJson(response);

                            final String id = json.getString("id");
                            final String name = json.getString("name");
                            FacebookActivity.this.runOnUiThread(new Runnable() {
                                    public void run() {
                                        try{ 
                                            username.setText("Welcome: " + name+"\n ID: "+id); //the error points to this line
                                            pb.setVisibility(ProgressBar.GONE);
                                        }catch(Exception e){
                                            e.printStackTrace();
                                        }
                                    }
                            });
                            postOnWall("The possibility of love between " + GlobalVars.getName1() + " and " + GlobalVars.getName2() + " is " + GlobalVars.getPercent() + "%!");
                    } catch (JSONException e) {
                            Log.d(TAG, "JSONException: " + e.getMessage());
                    } catch (FacebookError e) {
                            Log.d(TAG, "FacebookError: " + e.getMessage());
                    }
            }

            @Override
            public void onIOException(IOException e, Object state) {
                    Log.d(TAG, "IOException: " + e.getMessage());
            }

            @Override
            public void onFileNotFoundException(FileNotFoundException e,
                            Object state) {
                    Log.d(TAG, "FileNotFoundException: " + e.getMessage());
            }

            @Override
            public void onMalformedURLException(MalformedURLException e,
                            Object state) {
                    Log.d(TAG, "MalformedURLException: " + e.getMessage());
            }

            @Override
            public void onFacebookError(FacebookError e, Object state) {
                    Log.d(TAG, "FacebookError: " + e.getMessage());
            }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          mFacebook.authorizeCallback(requestCode, resultCode, data);
    }

    public void postOnWall(String msg) {
        Log.d("Tests graph API %%%%%$$$$%%%", msg);
         try {
                String response = mFacebook.request("me");
                Bundle parameters = new Bundle();
                parameters.putString("message", msg);
                parameters.putString("picture", "https://lh3.ggpht.com/f79UCpnLisZxO2P2C43f55YLvFpNco_cTcC-t9Ck-Qmqe5jwKbfnUvCh5N6-Te-mOw=w124");
                parameters.putString("link", "https://play.google.com/store/apps/details?id=com.b2creativedesigns.b2lovecalculator");

                response = mFacebook.request("me/feed", parameters,"POST");
                Log.d("Tests", "got response: " + response);
                if (response == null || response.equals("") || 
                        response.equals("false")) {
                   Log.v("Error", "Blank response");
                }
         } catch(Exception e) {
             e.printStackTrace();
         }
         finally {
             FacebookActivity.this.runOnUiThread(new Runnable() {
                  public void run() {
                      Toast.makeText(FacebookActivity.this, "Posted to Facebook", Toast.LENGTH_SHORT).show();
                  }
                });

         }
    }

}

The error points to the username.setText("Welcome: " + name+"\n ID: "+id); line, however in the stactrace I see both the name and id, printed by this line: Log.d(TAG, "Response: " + response.toString());

Why do I get this error?

Edit:

This is how I call the facebook post process by clicking on a button:

btnFB = (Button)findViewById(R.id.btnFB);
btnFB.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

             setConnection();
             getID(txtUserName, pbLogin);

        }
    });

The variables are defined like this, but there are no value assigned (from the tutorial):

TextView txtUserName;
ProgressBar pbLogin;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:10:33+00:00Added an answer on June 9, 2026 at 3:10 am

    As you stated above, when getID(txtUserName, pbLogin); is called, both txtUserName and pbLogin are null. This will cause your NullPointerException when you try to access them.

    Regardless of what the tutorial says, you need to have these fields assigned. You must have TextView and ProgressBar objects for when IDRequestListener is complete, or else your program will force close.

    So, to fix this, you must create your TextView and ProgressBar objects (through XML or through code). I would suspect that the tutorial you are using does say to do this. I would guess that you are supposed to define them using findViewById above the line where you assign btnFB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a Facebook application using Flash as3. In this application when ever
I have an iframe Facebook application (using Facebook's new JavaScript API) that needs to
i have a general question : i'd like to develop a facebook application using
I have integrated Facebook using library in my previous application and it works fine
I have an application in facebook platform (a trial application) and i am using
I have a Facebook desktop application and am using the Graph API . I
I have been working on a facebook application which will be using Graph API
I have created a facebook application using FaceBook ToolKit for .Net, What I am
I am using Facebook in my music application where user post comment on wall
I have really simple few lines of Facebook app, using the new Facebook API:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.