0

I am getting this NULL POINTER EXCEPTION ERROR. Need to fix this.

Trying to display the data in Table, In logs the data seems to be fetched, but its not displaying it in table format.

try {
                        jsonArray = new JSONArray(respString);
                        Log.d("jsonArray",jsonArray.toString());
                        TableRow[] tr_head = new TableRow[jsonArray.length()];
                        JSONObject jobj = null;
                        for(int i=0;i<jsonArray.length();i++){
                            jobj = jsonArray.getJSONObject(i);
                            tr_head[i] = new TableRow(getApplicationContext());
                            tr_head[i].setBackgroundColor(Color.GRAY);
                            tr_head[i].setLayoutParams(new TableRow.LayoutParams(
                                    ViewGroup.LayoutParams.MATCH_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT));
                            TextView tv_item1 = new TextView(getApplicationContext());
                            TextView tv_item2 = new TextView(getApplicationContext());
                            TextView tv_item3 = new TextView(getApplicationContext());
                            TextView tv_item4 = new TextView(getApplicationContext());
                            Log.d("Table Name",jobj.getString("tb_name"));
                            tv_item1.setText(jobj.getString("tb_name"));
                            tv_item1.setGravity(Gravity.CENTER);
                            tv_item2.setText(jobj.getString("cust_name"));
                            tv_item2.setGravity(Gravity.CENTER);
                            tv_item3.setText(jobj.getString("ord_date"));
                            tv_item3.setGravity(Gravity.CENTER);
                            tv_item4.setText(jobj.getString("ord_time"));
                            tv_item4.setGravity(Gravity.CENTER);
                            tr_head[i].addView(tv_item1);
                            tr_head[i].addView(tv_item2);
                            tr_head[i].addView(tv_item3);
                            tr_head[i].addView(tv_item4);
                            t1.addView(tr_head[i], new TableLayout.LayoutParams(
                                    ViewGroup.LayoutParams.MATCH_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT));

                        }

0 Answers0