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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:14:18+00:00 2026-06-15T01:14:18+00:00

So, Im getting a JSON from a REST server and I want to fill

  • 0

So,
Im getting a JSON from a REST server and I want to fill a ListView with its info. What I have is:

public class MyReservations extends ListActivity {
....
class HTTPAssync implements Runnable {
        public void run () {
               ... //make the requestions and get a valida JSONObject (that has a JSONArray)
               try {
                    JSONObject jsonObject = new JSONObject(payload);
                    reservs = jsonObject.getJSONArray("reservs");
                    try {
                         listView.setAdapter(new JSONAdapter(MyReservations.this, reservs));
                    }

I have created a JSONAdapter as well:

class JSONAdapter extends BaseAdapter implements ListAdapter {

private final Activity activity;
private final JSONArray jsonArray;
private LayoutInflater mInflater;

public JSONAdapter(Activity activity, JSONArray jsonArray) {
    assert activity != null;
    assert jsonArray != null;

    this.jsonArray = jsonArray;
    this.activity = activity;
}


public int getCount() {

    return jsonArray.length();
}

public JSONObject getItem(int position) {

    return jsonArray.optJSONObject(position);
}

public long getItemId(int position) {
    JSONObject jsonObject = getItem(position);

    return jsonObject.optLong("id");
}

public View getView(int position, View view, ViewGroup parent) {
    if (view == null)
        view = activity.getLayoutInflater().inflate(R.layout.reservation, null);

    JSONObject jsonObject = getItem(position);  
    view = mInflater.inflate(R.layout.reservation, null);

    ((TextView) view.findViewById(R.id.reservationCourse)).setText("MOTHAFOCKA");

    return view;
}
}

But when I make new Thread(new HTTPAssync()).start(); Im getting android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.. I tried to create a method and set the adapter from it, but got the same error. How can I do it?

  • 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-15T01:14:19+00:00Added an answer on June 15, 2026 at 1:14 am

    It’s not the problem of JSON. You must use android.os.Handler. There are two main uses for a Handler:

    (1) to schedule messages and runnables to be executed as some point in the future;

    (2) to enqueue an action to be performed on a different thread than your own.

    Example:

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
    
            final Object obj = msg.obj;
    
            switch (msg.what) {
            case MODE_DELETE:
                this.post(new Runnable() {
                    public void run() {             
                        performDelete();
                    }
                }); 
                break;
            case ON_SERVICE_STATUS_CHAGED:
                ((LauncherUI)mContext).updateUI();  
                break;
            case ON_DISPLAY_TOAST:
                Toast.makeText(mContext, obj.toString(),Toast.LENGTH_SHORT).show();
                break;
            case GET_USER_INPUT:
                handleUserInputRequest();
                break;
                        // .... 
            default:
                super.handleMessage(msg);
            }
        }
    };
    

    And here is a call example:

    mHandler.sendMessage(mHandler.obtainMessage(ON_DISPLAY_TOAST, "show toast"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this json string info from the server : {members:[[sd2840d,Johny],[jkld341,Marry]]} So I store
I am doing a rest call and getting a json file from the server
Getting Json from the Server and displaying it in the grid is relatively straight
Hi friends i'm getting json from server (using kohana framework 3.0) like this.... {
I have a jersey client that is getting JSON from a source that I
Im getting a JSON from a server, and when I type the url into
I am getting JSON response from the server..Inside that JSON string i am having
I am getting JSON string from website. I have data which looks like this
I am getting a JSON in response from server: { width: 765, height: 990,
I'm getting a json object from the server. If the json object has redirect

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.