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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:47:53+00:00 2026-06-11T19:47:53+00:00

I am working in android.In my project there is a JSON parsing field for

  • 0

I am working in android.In my project there is a JSON parsing field for that i implemented AsyncTask but i got the following error in my code. can anyone solve this out and help me in completing my project.enter image description here

following is my class….

    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.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;



    public class MyListActivity extends ListActivity {

        // url to make request
        private static String url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Sydney&sensor=true&key=AIzaSyD38pak_katUfSR92WE2_O2b9y0JSp5htA";



        // JSON Node names
        private static final String TAG_CONTACTS = "results";
        private static final String TAG_ID = "id";
        private static final String TAG_NAME = "name";
        private static final String TAG_ADDRESS = "formatted_address";
        private static final String TAG_GENDER = "rating";

        // contacts JSONArray
        JSONArray contacts = null;

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

        }

    class LoadData extends AsyncTask<String, String, String>
        {
        // Hashmap for ListView
            ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
        protected String doInBackground(String... args) {

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

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

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

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

                    // Storing each json item in variable
                    String id = c.getString(TAG_ID);
                    String name = c.getString(TAG_NAME);
    //              String email = c.getString(TAG_EMAIL);
                    String formatted_address = c.getString(TAG_ADDRESS);
                    String rating = c.getString(TAG_GENDER);

                    // Phone number is agin JSON Object
    //              JSONObject phone = c.getJSONObject(TAG_PHONE);
    //              String mobile = phone.getString(TAG_PHONE_MOBILE);
    //              String home = phone.getString(TAG_PHONE_HOME);
    //              String office = phone.getString(TAG_PHONE_OFFICE);

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

                    // adding each child node to HashMap key => value
                    map.put(TAG_ID, id);
                    map.put(TAG_NAME, name);
                    map.put(TAG_ADDRESS, formatted_address);
                    map.put(TAG_GENDER, rating);
    //              map.put(TAG_EMAIL, email);
    //              map.put(TAG_PHONE_MOBILE, mobile);

                    // adding HashList to ArrayList
                    contactList.add(map);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }    
        protected void onPostExecute(String file_url) {
            /**
             * Updating parsed JSON data into ListView
             * */
            ListAdapter adapter = new SimpleAdapter(this, contactList,
                    R.layout.listview_item_row,
                    new String[] { TAG_NAME, TAG_ADDRESS, TAG_GENDER,}, new int[] {
                            R.id.txtTitle, R.id.txtTitle1, R.id.txtTitle3 });

            setListAdapter(adapter);

            // selecting single ListView item
            ListView lv = getListView();

            // Launching new screen on Selecting Single ListItem
            lv.setOnItemClickListener(new OnItemClickListener() {


                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // getting values from selected ListItem
    //              String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
    //              String cost = ((TextView) view.findViewById(R.id.formatted_address)).getText().toString();
    //              String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();

                    // Starting new intent
                    Intent in = new Intent(getApplicationContext(), ProfileViewActivity.class);
    //              in.putExtra(TAG_NAME, name);
    //              in.putExtra(TAG_EMAIL, cost);
    //              in.putExtra(TAG_PHONE_MOBILE, description);
                    startActivity(in);

                }
            });

            }

    }
    }
  • 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-11T19:47:54+00:00Added an answer on June 11, 2026 at 7:47 pm
    ListAdapter adapter = new SimpleAdapter(this, contactList,
                    R.layout.listview_item_row,
                    new String[] { TAG_NAME, TAG_ADDRESS, TAG_GENDER,}, new int[] {
                            R.id.txtTitle, R.id.txtTitle1, R.id.txtTitle3 });
    

    replace this

    with MyListActivity.this

    ListAdapter adapter = new SimpleAdapter(MyListActivity.this, contactList,
                    R.layout.listview_item_row,
                    new String[] { TAG_NAME, TAG_ADDRESS, TAG_GENDER,}, new int[] {
                            R.id.txtTitle, R.id.txtTitle1, R.id.txtTitle3 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an Android project I'm working on that, ultimately, will require me to
I'm working with SQLite in my android project. There is a feature that is
I'm working on an Android project that focuses on knowing how close you are
I am working on a android project. I n that I have to deal
I am nearing completion of a project I am working on using Android, but
The project I'm currently working on requires me to code up the android portion
I'm working on an Android project that consists of several different Activities all associated
I have a semester long project that I have been working on in Android
I have an Android project, which I'm working on in Eclipse. There are no
I am currently working on android project where I am using a custom list

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.