Android - cannot populate a TableView with JSONArray data
i'm tryng to populate a TableLayout witth data that i get from a MySql database, i get the data from a php script that execute the query and return a JSONArray.
The query seem to work and i get a correct JSONArray, but i get a NullPointerExeption while running this code:
JSONArray jArray = new JSONArray(result);
TableLayout tl = (TableLayout) findViewById(R.layout.list);
TableRow tr = new TableRow(this);
TextView title = new TextView(this);
TextView author = new TextView(this);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
title.setText(json_data.getString("title").toString());
author.setText(json_data.getString("author").toS开发者_StackOverflow中文版tring());
tr.addView(title);
tr.addView(author);
tl.addView(tr);
tr.removeAllViews();
}
"result" contain a valid JSONArray, probably something go wrong in the for cycle, but i don't understand where is the error!
Thanks for your help!
精彩评论