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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:04:54+00:00 2026-06-15T19:04:54+00:00

I am trying to load data from a JSON web service and display it

  • 0

I am trying to load data from a JSON web service and display it in a List View, this is my first time to use JSON and I am still beginner, so any one please tell me what is the problem

package com.androidhive.jsonparsing;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;

public class AndroidJSONParsingActivity extends ListActivity {

    // url to make request
    private static String url = "my url";

    // JSON Node names
     String TAG_CONTACTS = "TAG_CONTACTS";
     String Id = "Id";
     String DoctorName = "DoctorName";
     String ImageName = "ImageName";


    // contacts JSONArray
    JSONArray Doctors = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Hashmap for ListView
        ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();

        // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(url);

        try {
            // Getting Array of Contacts
            Doctors = json.getJSONArray(TAG_CONTACTS);

            // looping through All Contacts
            for(int i = 0; i < Doctors.length(); i++){
                JSONObject c = Doctors.getJSONObject(i);

                // Storing each json item in variable
//               String Id =  c.getString("Id");
//               String DoctorName =  c.getString("DoctorName");
//               String ImageName =  c.getString("ImageName");
//          

                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map.put("Id", c.getString("Id"));
                map.put("DoctorName", c.getString("DoctorName"));
                map.put("ImageName", c.getString("ImageName"));

                // adding HashList to ArrayList
                contactList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }


        /**
         * Updating parsed JSON data into ListView
         * */
        ListAdapter adapter = new SimpleAdapter(this, contactList,
                R.layout.list_item,
                new String[] { DoctorName, ImageName }, new int[] {
                        R.id.name, R.id.image });

        setListAdapter(adapter);


    }

}

package com.androidhive.jsonparsing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    public JSONObject getJSONFromUrl(String url) {

        // Making HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}

when i run it , it gives me this warning

12-13 12:41:57.052: W/System.err(542): org.json.JSONException: No value for TAG_CONTACTS
12-13 12:41:57.052: W/System.err(542):  at org.json.JSONObject.get(JSONObject.java:354)
12-13 12:41:57.052: W/System.err(542):  at org.json.JSONObject.getJSONArray(JSONObject.java:544)
12-13 12:41:57.052: W/System.err(542):  at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:56)
12-13 12:41:57.063: W/System.err(542):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-13 12:41:57.063: W/System.err(542):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 12:41:57.072: W/System.err(542):  at android.os.Looper.loop(Looper.java:123)
12-13 12:41:57.072: W/System.err(542):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-13 12:41:57.072: W/System.err(542):  at java.lang.reflect.Method.invokeNative(Native Method)
12-13 12:41:57.072: W/System.err(542):  at java.lang.reflect.Method.invoke(Method.java:507)
12-13 12:41:57.072: W/System.err(542):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

and it opens an empty screen ! what is the problem ?

  • 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-15T19:04:55+00:00Added an answer on June 15, 2026 at 7:04 pm

    You are passing a wrong name for the JSON Array.. org.json.JSONException: No value for TAG_CONTACTS
    it should be:

    // Getting Array of Contacts
    Doctors = json.getJSONArray("Doctors");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load and parse json data from an external source into a
I am trying to load data asyncronously but on the first time, no progressbar
I'm trying to load a jqGrid from json data made via a REST call.
I'm trying to load data from an external .js file, containing a JSON representation
I'm trying to load data from the jsp response which is a JSON using
I am trying to get data from web services from my app to load
My Problem I am trying to load JSON encoded data from a remote site
Iam trying to return json data from codeigniter view. but my code is not
So I load my custom object from a web service and am trying to
I am trying to populate a jqGrid with data from a web service. I

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.