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

  • Home
  • SEARCH
  • 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 9162447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:12:51+00:00 2026-06-17T14:12:51+00:00

i have following code to parse a JSon response from Facebook.: doInBackground(JSONObject… params) {

  • 0

i have following code to parse a JSon response from Facebook.:

doInBackground(JSONObject... params) {
   try {
     JSONArray posts = params[0].getJSONArray("notifications");
     notifications.clear();
     for (int i = 0; i < posts.length(); i++) {
     Notifications info = new Notifications();
     JSONObject tempobj = (JSONObject) posts.get(i);
     //some code here related to parse...
       }
     }catch(Ex...xxx){}
     sort();
}

and my sort method is as:

private void sort() {
        mActivity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Log.e("sort called", "sort called" + actualListView.getSelectedItemPosition());
                try {
                    Collections.sort(notifications, new Comparator<Notifications>() {

                        @Override
                        public int compare(Notifications object1, Notifications object2) {

                            int time1 = Integer.parseInt(object1.updated_time);
                            int time2 = Integer.parseInt(object2.updated_time);
                            if (time1 < time2)
                                return 1;
                            else if (time1 > time2)
                                return -1;
                            return 0;
                        }
                    });
                } catch (Exception e) {
                    Log.e("java.util.Collections", "Error occurred in sorting the notifications");
                    e.printStackTrace();
                }
            }
        });

    }

and in onPostExecute method i call another method to update UI.:
but i am facing exception.
Logs are here:

STACK_TRACE=java.lang.ExceptionInInitializerError
at
com.platinumapps.fragments.NotificationFragment$NotificationRequestListener.onComplete(NotificationFragment.java:241)
at
com.facebook.android.AsyncFacebookRunner$3.run(AsyncFacebookRunner.java:391)
Caused by: java.lang.RuntimeException: Can't create handler inside thread
that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
... 2 more
java.lang.RuntimeException: Can't create handler inside thread that has not
called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
at
com.platinumapps.fragments.NotificationFragment$NotificationRequestListener.onComplete(NotificationFragment.java:241)
at
com.facebook.android.AsyncFacebookRunner$3.run(AsyncFacebookRunner.java:391)

Whats wrong with code? Please help me. Thanks.

  • 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-17T14:12:52+00:00Added an answer on June 17, 2026 at 2:12 pm

    You are calling sort() in doInBackground, which calls runOnUiThread … move that pert to onPostExecute, as you cannot call runOnUiThread in doInBackground…

     doInBackground(JSONObject... params) {
     try {
     JSONArray posts = params[0].getJSONArray("notifications");
     notifications.clear();
     for (int i = 0; i < posts.length(); i++) {
     Notifications info = new Notifications();
     JSONObject tempobj = (JSONObject) posts.get(i);
     //some code here related to parse...
       }
     }catch(Ex...xxx){}
     //sort();  //need to be moved
    }
    
    onPostExecute() {
       sort();
      .....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok i have this following code that parses JSON from an ajax response using
I have used following code to convert string to json and parse it. String
I have the following code : XDocument xResponse = XDocument.Parse(strXMLResponse); var vMyData = from
I have the following code which is executed from the command line: import cgi,time,os,json,sys,zipfile,urllib2
I have used the following Java code from Yahoo to get search results response
I want to pull posts from a users Facebook wall. The following code snippet
I Have following Json as { meta: { code: 200 }, response: { deals:
I have written following code to get JSON result from webservice. function SaveUploadedDataInDB(fileName) {
In my controller I have the following code to generate a Json response whenever
I have the following code to display JSON results from an AJAX request as

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.