开发者

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜