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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:03:58+00:00 2026-05-14T20:03:58+00:00

I am trying to retrieve the values from the following url: http://rentopoly.com/ajax.php?query=Bo . I

  • 0

I am trying to retrieve the values from the following url: http://rentopoly.com/ajax.php?query=Bo. I want to get the values of all the suggestions to be displayed in a list view one by one. This is how i want to do…

public class AlertsAdd {
 public ArrayList <JSONObject> retrieveJSONArray(String urlString) {
  String result = queryRESTurl(urlString);
  ArrayList <JSONObject> ALERTS = new ArrayList <JSONObject> ();
  if (result != null) {

   try {
    JSONObject json = new JSONObject(result);
    JSONArray alertsArray = json.getJSONArray("suggestions");
    for (int a = 0; a < alertsArray.length(); a++) {
     JSONObject alertitem = alertsArray.getJSONObject(a);
     ALERTS.add(alertitem);
    }
    return ALERTS;
   } catch (JSONException e) {
    Log.e("JSON", "There was an error parsing the JSON", e);
   }
  }
  JSONObject myObject = new JSONObject();
  try {
   myObject.put("suggestions", myObject.getJSONArray("suggestions"));
   ALERTS.add(myObject);
  } catch (JSONException e1) {
   Log.e("JSON", "There was an error creating the JSONObject", e1);
  }
  return ALERTS;
 }
 private String queryRESTurl(String url) {
  // URLConnection connection;
  HttpClient httpclient = new DefaultHttpClient();
  HttpGet httpget = new HttpGet(url);
  HttpResponse response;
  try {
   response = httpclient.execute(httpget);
   HttpEntity entity = response.getEntity();
   if (entity != null) {
    InputStream instream = entity.getContent();
    String result = convertStreamToString(instream);
    instream.close();
    return result;
   }
  } catch (ClientProtocolException e) {
   Log.e("REST", "There was a protocol based error", e);
  } catch (IOException e) {
   Log.e("REST", "There was an IO Stream related error", e);
  }
  return null;
 }

 /**
  * To convert the InputStream to String we use the
  * BufferedReader.readLine() method. We iterate until the BufferedReader
  * return null which means there's no more data to read. Each line will
  * appended to a StringBuilder and returned as String.
  */
 private String convertStreamToString(InputStream is) {
  BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  StringBuilder sb = new StringBuilder();

  String line = null;
  try {
   while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
   }
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    is.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  return sb.toString();
 }
}

Here’s the adapter code…

public class AlertsAdapter extends ArrayAdapter <JSONObject> {
 public AlertsAdapter(Activity activity, List <JSONObject> alerts) {
  super(activity, 0, alerts);
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  Activity activity = (Activity) getContext();
  LayoutInflater inflater = activity.getLayoutInflater();
  View rowView = inflater.inflate(R.layout.list_text, null);
  JSONObject imageAndText = getItem(position);
  TextView textView = (TextView) rowView.findViewById(R.id.last_build_stat);
  try {
   textView.setText((String) imageAndText.get("suggestions"));
  } catch (JSONException e) {
   textView.setText("JSON Exception");
  }
  return rowView;
 }
}

Here’s the logcat…

    04-30 13:09:46.656: INFO/ActivityManager(584): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.WorldToyota/.Alerts }
04-30 13:09:50.417: ERROR/JSON(924): There was an error parsing the JSON
04-30 13:09:50.417: ERROR/JSON(924): org.json.JSONException: JSONArray[0] is not a JSONObject.
04-30 13:09:50.417: ERROR/JSON(924):     at org.json.JSONArray.getJSONObject(JSONArray.java:268)
04-30 13:09:50.417: ERROR/JSON(924):     at com.WorldToyota.AlertsAdd.retrieveJSONArray(AlertsAdd.java:30)
04-30 13:09:50.417: ERROR/JSON(924):     at com.WorldToyota.Alerts.onCreate(Alerts.java:20)
04-30 13:09:50.417: ERROR/JSON(924):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-30 13:09:50.417: ERROR/JSON(924):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
04-30 13:09:50.417: ERROR/JSON(924):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
04-30 13:09:50.417: ERROR/JSON(924):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-30 13:09:50.417: ERROR/JSON(924):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-30 13:09:50.417: ERROR/JSON(924):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 13:09:50.417: ERROR/JSON(924):     at android.os.Looper.loop(Looper.java:123)
04-30 13:09:50.417: ERROR/JSON(924):     at android.app.ActivityThread.main(ActivityThread.java:4203)
04-30 13:09:50.417: ERROR/JSON(924):     at java.lang.reflect.Method.invokeNative(Native Method)
04-30 13:09:50.417: ERROR/JSON(924):     at java.lang.reflect.Method.invoke(Method.java:521)
04-30 13:09:50.417: ERROR/JSON(924):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-30 13:09:50.417: ERROR/JSON(924):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-30 13:09:50.417: ERROR/JSON(924):     at dalvik.system.NativeStart.main(Native Method)
04-30 13:09:50.688: ERROR/JSON(924): There was an error creating the JSONObject
04-30 13:09:50.688: ERROR/JSON(924): org.json.JSONException: JSONObject["suggestions"] not found.
04-30 13:09:50.688: ERROR/JSON(924):     at org.json.JSONObject.get(JSONObject.java:287)
04-30 13:09:50.688: ERROR/JSON(924):     at org.json.JSONObject.getJSONArray(JSONObject.java:362)
04-30 13:09:50.688: ERROR/JSON(924):     at com.WorldToyota.AlertsAdd.retrieveJSONArray(AlertsAdd.java:41)
04-30 13:09:50.688: ERROR/JSON(924):     at com.WorldToyota.Alerts.onCreate(Alerts.java:20)
04-30 13:09:50.688: ERROR/JSON(924):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-30 13:09:50.688: ERROR/JSON(924):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
04-30 13:09:50.688: ERROR/JSON(924):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
04-30 13:09:50.688: ERROR/JSON(924):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-30 13:09:50.688: ERROR/JSON(924):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-30 13:09:50.688: ERROR/JSON(924):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 13:09:50.688: ERROR/JSON(924):     at android.os.Looper.loop(Looper.java:123)
04-30 13:09:50.688: ERROR/JSON(924):     at android.app.ActivityThread.main(ActivityThread.java:4203)
04-30 13:09:50.688: ERROR/JSON(924):     at java.lang.reflect.Method.invokeNative(Native Method)
04-30 13:09:50.688: ERROR/JSON(924):     at java.lang.reflect.Method.invoke(Method.java:521)
04-30 13:09:50.688: ERROR/JSON(924):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-30 13:09:50.688: ERROR/JSON(924):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-30 13:09:50.688: ERROR/JSON(924):     at dalvik.system.NativeStart.main(Native Method)

Plz help me parsing this script and displaying the values in list format….

  • 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-14T20:03:58+00:00Added an answer on May 14, 2026 at 8:03 pm

    check out this example – uses the same service you are trying to access and is also based on Android.

    http://damonsk.com/2010/01/jsonarray-httpclient-android/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I am trying to retrieve information from a web service call. The following is
Trying out the following, will result in error. How do I retrieve the values
I'm trying to retrieve a 'campaign' code from the URL when a user visits
I am trying to retrieve the values of 'Title' using the following codes: private
I have a serious problem. Firstly, I am trying to retrieve values from my
I was trying to retrieve value from two tables by joining, but few values
I'm receiving the following error with this page while trying to retrieve information from
I have next problem, when I'm trying to retrieve value from xforms:select elements I
I am trying to retrieve a value from an Array. Here is the code:

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.