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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:37:30+00:00 2026-05-31T03:37:30+00:00

I have an activity class file and an adapter class file. It will be

  • 0

I have an activity class file and an adapter class file. It will be displaying a list of items loaded from the webpage. But I am having forced close on my WallPostListener. What is the problem here?

LOGCAT ERROR CODE

03-07 11:28:23.919: ERROR/AndroidRuntime(525): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
03-07 11:28:23.919: ERROR/AndroidRuntime(525):     at android.os.Handler.<init>(Handler.java:121)
03-07 11:28:23.919: ERROR/AndroidRuntime(525):     at android.widget.Toast.<init>(Toast.java:68)
03-07 11:28:23.919: ERROR/AndroidRuntime(525):     at android.widget.Toast.makeText(Toast.java:231)
03-07 11:28:23.919: ERROR/AndroidRuntime(525):     at spca.org.sg.Cats$WallPostListener.onComplete(Cats.java:175)
03-07 11:28:23.919: ERROR/AndroidRuntime(525):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:209)

MyActivity.java

public class MyActivity extends Activity {

private static final String targetURL ="http://www.google.com/image/myself";
ListView list;
private Handler mRunOnUi = new Handler();
private ProgressDialog mProgress;
ProgressDialog dialog;
private String[] mStrings = {};
private String[] dStrings = {};
private String date;

private String messageToPost;
Facebook facebook = new Facebook("110928043842377");
private SharedPreferences mPrefs;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cats);

    new TheTask().execute();
    list=(ListView)findViewById(R.id.list);                  
}

protected class TheTask extends AsyncTask<Void, Void, MyResultClass >{

    protected void onPreExecute() {
        dialog = ProgressDialog.show(MyActivity.this, "Retrieving Information", "Please wait for a few seconds...", true, false);
        dialog.setCancelable(true);
    }

    protected MyResultClass doInBackground(Void... params) {
        searchContent();
        MyResultClass result = new MyResultClass();
        result.mStrings = mStrings;
        result.dStrings = dStrings;
        result.date = date;
        return result;          
    }   

    protected void onPostExecute(MyResultClass result) {            
        dStrings = result.dStrings;
        mStrings = result.mStrings;
        date = result.date;
        LazyAdapter adapter = new LazyAdapter(MyActivity.this, mStrings, dStrings);
        list.setAdapter(adapter);

        adapter.setTaskListener(new FBookTaskListener(){
            public void doAuthentication()
            {
                    // here all your FB authentication related stuff.

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

                /*
                 * Only call authorize if the access_token has expired.
                 */
                if(!facebook.isSessionValid()) {

                facebook.authorize(Myactivity.this, new String[] { "publish_stream", "read_stream", "publish_checkins"}, new DialogListener() {
                    @Override
                    public void onComplete(Bundle values) 
                    {
                        SharedPreferences.Editor editor = mPrefs.edit();
                        editor.putString("access_token", facebook.getAccessToken());
                        editor.putLong("access_expires", facebook.getAccessExpires());
                        editor.commit();
                    }

                    @Override
                    public void onFacebookError(FacebookError error) {}

                    @Override
                    public void onError(DialogError e) {}

                    @Override
                    public void onCancel() {}
                });
            }

                Log.d("Test", "Authorizing completed");
            }
            public void postToWall(String data)
            {
                Log.d("Test", "Start of postToWall");
                postToFacebook(messageToPost);
                System.out.println("postToWall complete");
            }
        });

        dialog.dismiss();
    }       
}

    class MyResultClass
    { 
        public String[] mStrings; 
        public String[] dStrings;
        public String date;
    }

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

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

    private void postToFacebook(String message) {
        mProgress.setMessage("Posting ...");
        mProgress.show();

        AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(facebook);

        Bundle params = new Bundle();

        //params.putString("message", "Visit me here!");
        params.putString("name", "Pinky");
        params.putString("caption", "google.com");
        params.putString("link", "http://www.google.com");
        params.putString("description", "Visit ");
        //params.putString("picture", data);

        //facebook.dialog(this, "feed", new PostDialogListener());
        mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());

    }//close posttofacebook

    private final class WallPostListener extends BaseRequestListener {
        public void onComplete(final String response) {
            mRunOnUi.post(new Runnable() {
                @Override
                public void run() {
                    mProgress.cancel();

                    Toast.makeText(MyActivity.this, "Posted to Facebook", Toast.LENGTH_SHORT).show();
                }
            });
        }//close oncomplete
    }//close wallpostlistener

public void searchContent()
{
    String imageC = "";
    String textC = "";

    try {

        URL url = new URL(targetURL);

        // Make the connection
        URLConnection conn = url.openConnection();
        BufferedReader reader = new BufferedReader(
         new InputStreamReader(conn.getInputStream()));

        String line = reader.readLine();
        Pattern sChar = Pattern.compile("&.*?;");
        line.replaceAll("\\<.*?\\>", "");
        Matcher msChar = sChar.matcher(line);
        while (msChar.find()) line = msChar.replaceAll("");

        while (line != null) {

            if(line.contains("../../"))
            {

                int startIndex = line.indexOf("../../") + 6;
                int endIndex = line.indexOf(">", startIndex + 1);
                String abc = "http://www.google.com/image/myself";
                String imageSrc = line.substring(startIndex,endIndex);
                //complete full url
                String xyz = abc +imageSrc;
                xyz = xyz.substring(0,xyz.indexOf('"'));
                xyz = xyz +";";
                xyz = xyz.replaceAll(" ", "%20");
                imageC += xyz;                  
                mStrings = imageC.split(";");
                line = reader.readLine();
            }

            if(line.contains("../../") == false)
            {
                line = reader.readLine();
            }

            if (line.contains("Gnametag"))
            {
                int startIndex = line.indexOf("Gnametag") + 10;
                int endIndex = line.indexOf("<", startIndex + 1);
                String gname = line.substring(startIndex,endIndex);
                textC = textC.replaceAll("</span>", "");
                textC += "Name: "+gname+ "\n";
            }


                if (line.contains("Age"))
                {
                    textC += "Age: "+reader.readLine() + "\n" + ";";
                    textC = textC.replaceAll("                  ", "");
                    dStrings = textC.split(";");
                }

            if (line.contains("Last Update"))
            {
                int startIndex = line.indexOf("Last Update") + 16;
                int endIndex = line.indexOf("</td>", startIndex + 1);
                date = line.substring(startIndex,endIndex);
                reader.close();
            }                               
        }           

        // Close the reader
        reader.close();

    } catch (Exception ex) {
        ex.printStackTrace();           
    }       
}        
}

Adapter.java

public class LazyAdapter extends BaseAdapter {
FBookTaskListener taskListener;
Facebook facebook = new Facebook("110928043842377");
private Activity activity;
private String[] data;
private String[] text;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;

private ProgressDialog mProgress;
private Handler mRunOnUi = new Handler();

String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;

public void setTaskListener(FBookTaskListener listener)
{
    this.taskListener = listener;
}

public LazyAdapter(Activity a, String[] d, String[] t) {
    activity = a;
    data=d;
    text = t;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());        

}

public int getCount() {
    return data.length;
}    

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public static class ViewHolder{
    public TextView text;
    public ImageView image;
}

public View getView(final int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    ViewHolder holder;
    if(convertView==null){
        vi = inflater.inflate(R.layout.item, null);
        holder=new ViewHolder();
        holder.text=(TextView)vi.findViewById(R.id.text);;
        holder.image=(ImageView)vi.findViewById(R.id.image);
        vi.setTag(holder);

        ImageButton fbBtn = (ImageButton) vi.findViewById(R.id.fb);

        fbBtn.setOnClickListener(
                new Button.OnClickListener() {
                    public void onClick(View v) 
                    {
                        taskListener.doAuthentication();
                            taskListener.postToWall();}}
            );

    }
    else
    holder=(ViewHolder)vi.getTag();

    holder.text.setText(text[position]);
    holder.image.setTag(data[position]);
    imageLoader.DisplayImage(data[position], activity, holder.image);
    return vi;        
}//close getView

public static interface FBookTaskListener{
    public void doAuthentication(); //paramas may be added if needed
    public void postToWall(String data);  //paramas may be added if needed
}

}
  • 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-05-31T03:37:32+00:00Added an answer on May 31, 2026 at 3:37 am

    Maybe you can try this instead of the request. Use a dialog for custom message.

    Replace .request with .dialog.

    facebook.dialog(this, "feed", params, new PostDialogListener());

    And add this to your Activity

    public class PostDialogListener extends BaseDialogListener {
        @Override
        public void onComplete(Bundle values) {
            final String postId = values.getString("post_id");
            if (postId != null) {
            } else {
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of objects called Activity: class Activity { public Date activityDate;
I have 3 classes in my example: Class A, the main activity. Class A
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity which shows some List entries. When I click on a
I have an Android activity that displays a list of log entries (using a
I have a ListView that uses a customized adapter, but I can't click on
I have ListView activity class: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] naziviMolitvi =
These are the activity and Image Adapter that I used for my CoverFlow. But
I have a simple Hello World application public class TestLeaksOnFinish extends Activity { static
I have made a custom adapter class here is the code public class CustomArrayAdapterForReceipts

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.