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 8388469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:28:45+00:00 2026-06-09T18:28:45+00:00

I am creating a simple app to get and post some information on any

  • 0

I am creating a simple app to get and post some information on any facebook account!

I cant get past logging in and out. ive check out the facebook tutorial website but invain! i have been on the issue for days now.

This is the code that ive written. I need to know where i have messed up. The code builds with no errors but crashes when i click the ‘Login’ Button.

Ive also copied the LogCat after the code.

package com.thenewboston.travis;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.facebook.android.*;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.Facebook.*;

public class FbExample extends Activity implements OnClickListener {

Facebook facebook = new Facebook("xxxxxxx");
AsyncFacebookRunner mAsyncRunner;
Button login;
TextView logoutResult;
private SharedPreferences mPrefs;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fbexample);
    login = (Button) findViewById(R.id.bLogin);
    logoutResult = (TextView) findViewById(R.id.tvLogoutResult);
    login.setOnClickListener(this);
    mPrefs = getPreferences(MODE_PRIVATE);
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);
    if (access_token != null) {
        facebook.setAccessToken(access_token);
    }
    if (expires != 0) {
        facebook.setAccessExpires(expires);
    }

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    if (v.getId() == R.id.bLogin) {
        if (!facebook.isSessionValid()) {
            facebook.authorize(this, new String[] {}, new DialogListener() {
                public void onComplete(Bundle values) {
                    SharedPreferences.Editor editor = mPrefs.edit();
                    editor.putString("access_token",
                            facebook.getAccessToken());
                    editor.putLong("access_expires",
                            facebook.getAccessExpires());
                    editor.commit();
                    login.setText("Logout");

                }

                public void onFacebookError(FacebookError error) {
                }

                public void onError(DialogError e) {
                }

                public void onCancel() {
                }
            });
        }
        if (facebook.isSessionValid()) {
            mAsyncRunner.logout(this,
                    new RequestListener() {

                        public void onComplete(String response, Object state) {
                            login.setText("Login");
                        }

                        public void onIOException(IOException e,
                                Object state) {
                            String error = e.getMessage();
                            logoutResult.setText(error);

                        }

                        public void onFileNotFoundException(
                                FileNotFoundException e, Object state) {
                            String error = e.getMessage();
                            logoutResult.setText(error);
                        }

                        public void onMalformedURLException(
                                MalformedURLException e, Object state) {
                            String error = e.getMessage();
                            logoutResult.setText(error);
                        }

                        public void onFacebookError(FacebookError e,
                                Object state) {
                            String error = e.getMessage();
                            logoutResult.setText(error);
                        }
                    });

        }
    }

}
}

LogCat

08-02 02:20:26.859: W/dalvikvm(302): threadid=1: thread exiting with uncaught
exception (group=0x4001d800)
08-02 02:20:26.878: E/AndroidRuntime(302): FATAL EXCEPTION: main
08-02 02:20:26.878: E/AndroidRuntime(302): java.lang.NullPointerException
08-02 02:20:26.878: E/AndroidRuntime(302):  at     com.thenewboston.travis.FbExample.onClick(FbExample.java:81)
08-02 02:20:26.878: E/AndroidRuntime(302):  at android.view.View.performClick(View.java:2408)
08-02 02:20:26.878: E/AndroidRuntime(302):  at android.view.View$PerformClick.run(View.java:8816)
08-02 02:20:26.878: E/AndroidRuntime(302):  at android.os.Handler.handleCallback(Handler.java:587)
08-02 02:20:26.878: E/AndroidRuntime(302):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-02 02:20:26.878: E/AndroidRuntime(302):  at android.os.Looper.loop(Looper.java:123)
08-02 02:20:26.878: E/AndroidRuntime(302):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-02 02:20:26.878: E/AndroidRuntime(302):  at java.lang.reflect.Method.invokeNative(Native Method)
08-02 02:20:26.878: E/AndroidRuntime(302):  at java.lang.reflect.Method.invoke(Method.java:521)
08-02 02:20:26.878: E/AndroidRuntime(302):  at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-02 02:20:26.878: E/AndroidRuntime(302):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-02 02:20:26.878: E/AndroidRuntime(302):  at dalvik.system.NativeStart.main(Native Method)
08-02 02:20:29.368: I/Process(302): Sending signal. PID: 302 SIG: 9
  • 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-09T18:28:46+00:00Added an answer on June 9, 2026 at 6:28 pm

    You did not instantiate mAsyncRunner before calling mAsyncRunner.logout()

    Can you change the following line:

     AsyncFacebookRunner mAsyncRunner;
    

    to

     AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    

    Please let me know if that helps.

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

Sidebar

Related Questions

I need some help with rally. I'm currently looking at creating a simple app
I'm creating a simple alarm clock app. The problem is that i get the
I am working on a simple Facebook App that will allow me to post
I am creating an app on facebook and I am trying to post to
I am creating simple app on Silverlight 4. In folder of View I have
I am creating a simple web app. There is a <video> element on the
my question is simple i think. I am creating a really simple app which
Good morning, A bit of background might help. I'm creating a very simple app
I'm currently learning rails by creating a simple project management app. I've gotten to
When creating a simple Flex 4.6 App, where the creationComplete-handler looks like this: protected

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.