hi im expanded a previous question i asked just to make it clearer. i'm trying to get a json feed from a url and then create a list of titles using a list adapter. my json feed consists of a thing called data inside that an array of news and inside that thing called title.
when i run the app it force closes. I've been told its because i have a string inside a for loop and no instance of it outside to go in the adapter. i am new to this so any help would be appreciated heres my code
try{
// Create a new HTTP Client
DefaultHttpClient defaultClient = new DefaultHttpClient();
// Setup the get request
HttpGet httpGetRequest = new HttpGet("jsonfeed");
// Execute the request in the client
HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
// Grab the response
BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
// Instantiate a JSON object from the request response
JSONObject jsonObject = new JSONObject(json);
JSONArray jArray = jsonObject.getJSONArray("news");
String oneObjectsItem1 = null;
for (int i=0; i < jArray.length(); i++)
{
JSONObject oneObject = jArray.getJSONObject(i);
// Pulling items from the array
String oneObjectsItem = oneObject.getString("title");
}
} catch(Exception e){
// In your production code handle any errors and catch the individual exceptions
e.printStackTrace();
}
setListAdapter ( new ArrayAdapter<String>(this, R.layout.single_item, oneObjectsItem));
ListView list = getListView();
list.setTextFilterEnabled(true);