-1

hi there I'm not getting any errors but for some reason its not filling my list the json feed has an array of news inside that is a tag called title and i want to display the titles in a list view. but at the moment it just displays a blank screen. heres my code

try {

    // Instantiate a JSON object from the request response
    JSONObject obj = new JSONObject(json);
    List<String> items = new ArrayList<String>();

    JSONArray jArray = obj.getJSONArray("news");

    for (int i = 0; i < jArray.length(); i++) {
        JSONObject oneObject = jArray.getJSONObject(i);
        items.add(oneObject.getString("title"));
    }

    setListAdapter(new ArrayAdapter<String>(this, R.layout.single_item,
            items));
    ListView list = getListView();
    list.setTextFilterEnabled(true);

    list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(),
                    ((TextView) arg1).getText(), 1000).show();
        }

    });

} catch (Exception e) {
    // In your production code handle any errors and catch the
    // individual exceptions
    e.printStackTrace();
}
Shashi
  • 12,487
  • 17
  • 65
  • 111
iamlukeyb
  • 6,487
  • 12
  • 29
  • 40
  • Please post a sample of the JSON you're trying to parse. We're not magicians ;) – Brian Roach Mar 09 '12 at 17:35
  • sorry heres the json {"code":200,"error":null,"data":{"news":[{"news_id":"8086","title":"Tickets for Player of the Year award on general sale", – iamlukeyb Mar 10 '12 at 23:17

1 Answers1

0

To start debugging something like this, figure out where the data is, and where it isn't. Android has some excellent debugging routines, the Log.v statements. Basically, start putting code like this in, and see where your problem lies. If you get it down to a specific thing that isn't working right, then give us the inputs to the block, the outputs your getting, and what it should be.

Log.v("JSON",""+items)
PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142
  • I have put that in but not getting anything in LogCat Log cat is only showing stuff from yesterday even though I've tried to use it a few times today and its not logging anything – iamlukeyb Mar 09 '12 at 17:38