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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:57:12+00:00 2026-06-01T17:57:12+00:00

i’m using facebook runner to apply some facebook api tesk. i want to check

  • 0

i’m using facebook runner to apply some facebook api tesk.
i want to check if i got a JSON object with data or and error message so i’m checking the “message” field to check if it’s null.
if it is not null and i have a massage, i want to display the message and exit the application.

this is my code in my activity:

public class Loader extends Activity implements FacebookConnectionListener, ServerDataListener {
    private TextView loaderStatus;
    private Facebook facebook;
    private AsyncFacebookRunner facebookRunner;
    private FacebookConnection facebookConnection;   

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loader);
        facebook = new Facebook(facebookAppId);
        facebookRunner = new AsyncFacebookRunner(facebook);
        facebookConnection = new FacebookConnection(this, 1);
        facebookRunner.request("me",facebookConnection);
    }

    @Override
    public void onFacebookResponse(final String response , int step) {
        final JSONObject facebookResults = convertToJSON(response);
        final Context thisContext = (Context) getBaseContext();
        String id = "", name = "", gender = "", homeTown = "";
        Drawable profilePicture = null;

        if (step == 1) {
            if (facebookResults.isNull("message")) {
                try {
                    id = facebookResults.getString("id");
                    name = facebookResults.getString("name");
                    gender = facebookResults.getString("gender");
                    JSONObject homeTownObject = (JSONObject) facebookResults.get("hometown");
                    homeTown = homeTownObject.getString("name");
                    profilePicture = getProfilePicture(id);

                } catch (JSONException e) { 
                    alert("Facebook", e.toString(), "Ok", thisContext);
                }
                facebookCurrentUser = new FacebookCurrentUser(id, name, gender);
                facebookCurrentUser.setHomeTown(homeTown);
                facebookCurrentUser.setProfilePicture(profilePicture);
                app.setFacebookCurrentUser(facebookCurrentUser);
                facebookConnection = new FacebookConnection(this, 2);   
                this.runOnUiThread(new Runnable() {
                public void run() {
                        loaderStatus.setText("Getting friends details");
                    }
                });
            }
            else {
                this.runOnUiThread(new Runnable() {
                    public void run() {
                        alert("Facebook", "Can't get user details! Please try again", "Ok", thisContext);
                    }
                }); 
            }           
        }

public void alert (String title, String message, String ok, Context listener)
{
    AlertDialog.Builder alert = new AlertDialog.Builder(listener);
    alert.setMessage(message);
    alert.setTitle(title);
    alert.setPositiveButton(ok, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();   
        }
    });
    alert.show();
}

this is FacebookConnection class:

public class FacebookConnection implements RequestListener {
    private FacebookConnectionListener listener;
    private int step;

    public FacebookConnection (FacebookConnectionListener listener, int step) {
        this.listener = listener;
        this.step = step;
    }

    public void updateFacebookListener(String response) {
        listener.onFacebookResponse(response, step);
    }

    @Override
    public void onComplete(String response, Object state) {
        updateFacebookListener(response);           
    }

    @Override
    public void onIOException(IOException e, Object state) { }

    @Override
    public void onFileNotFoundException(FileNotFoundException e, Object state) { }

    @Override
    public void onMalformedURLException(MalformedURLException e, Object state) { }

    @Override
    public void onFacebookError(FacebookError e, Object state) { }
 }

the FacebookConnectionListener interface:

public interface FacebookConnectionListener {
    public void onFacebookResponse(String response, int step);
}

my alerts keep giving me the :

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

and i can’t understand why.. help ?

  • 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-01T17:57:13+00:00Added an answer on June 1, 2026 at 5:57 pm

    Well, try this:

    public void alert (String title, String message, String ok) {
        this.runOnUiThread(new Runnable() {
            public void run() {
                AlertDialog alert = new AlertDialog.Builder(Loader.this).create();
                alert.setMessage(message);
                alert.setTitle(title);
                alert.setPositiveButton(ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });
                alert.show();
            }
        });
    }
    

    Instead of what you have now, and when you call it, just call it like any other method:

    this.alert("Facebook", "Can't get user details! Please try again", "Ok")
    

    I’m not exactly sure where it goes wrong, it even might have to do with you forgetting the create() part when constructing the dialog.

    Hope this will sort things for you.

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.