Re: [android-developers] Re: Retrieving the Json data into a list view...
Rahul As a followup go to my site again I have posted another tutorial to do this http://www.josecgomez.com Thanks! Sincerely Jose C Gomez http://www.josecgomez.com On Mon, May 3, 2010 at 9:20 AM, Rahul wrote: > Here's the log errors i m getting... > > 04-30 13:09:46.656: INFO/ActivityManager(584): Starting activity: > Intent { act=android.intent.action.MAIN > cat=[android.intent.category.LAUNCHER] flg=0x1000 > 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) > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send
Re: [android-developers] Re: Retrieving the Json data into a list view...
Rahul, This should solve your problem if you get stuck let me know. I just wrote this specifically to address your problem and for my own reference http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/ Sincerely Jose C Gomez http://www.josecgomez.com On Fri, Apr 30, 2010 at 8:16 AM, Rahul wrote: > I have done the following. But still i cant get the result... Can > anyone help me determine what the error is...Pl help me out... > > public class AlertsAdd { >public ArrayList retrieveJSONArray(String urlString) { >String result = queryRESTurl(urlString); >ArrayList ALERTS = new ArrayList(); >if (result != null) { > >try { >JSONObject json = new JSONObject(result); >Log.i("Info",json.toString()); > >JSONObject alertsObject = json.getJSONObject("alertid"); >ALERTS.add(alertsObject); > >return ALERTS; >} catch (JSONException e) { >Log.e("JSON", "There was an error parsing the JSON", > e); >} >} >JSONObject myObject = new JSONObject(); >try { >myObject.put("Alert Id",myObject.getJSONArray("alertid")); >ALERTS.add(myObject); >} catch (JSONException e1) { >Log.e("JSON", "There was an error creating the JSONObject", > e1); >} >return ALERTS; >} > > > public class AlertsAdapter extends ArrayAdapter { >public AlertsAdapter(Activity activity, List 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("alertid")); >} catch (JSONException e) { >textView.setText("JSON Exception"); >} > >return rowView; > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en