The json array format is
[{"restaurants": {
"items1": [{
"id": 4,
"item_name": "Special Pizza",
"image": ""
}, {
"id": 5,
"item_name": "Veg Cheese Pizza",
"image": ""
}]
"items2": [{
"id": 4,
"item_name": "Special Pizza",
"image": ""
}, {
"id": 5,
"item_name": "Veg Cheese Pizza",
"image": ""
}]
}}
I want to get the item1 & item2 to pass the value as a parent in Expandable ListView
and pass the item_name into child. What to do to get the parent name and set into the setter method?
class AsyncT1 extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
// http://abservetech.com/demoprojects/android/food_app/public/mobile/restaurant/restaurantresults
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://abservetechdemo.com/projects/android/food_app/public/mobile/restaurant/resdetails");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("res_id","1"));
nameValuePairs.add(new BasicNameValuePair("status","veg"));
nameValuePairs.add(new BasicNameValuePair("main_cat","pizza"));
// nameValuePairs.add(new BasicNameValuePair("group_id", group_id));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.e("mainToPost", "mainToPost" + nameValuePairs.toString());
/* execute */
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
InputStream inputStream = response.getEntity().getContent();
InputStreamToStringExample str = new InputStreamToStringExample();
String responseServer = str.getStringFromInputStream(inputStream);
Log.d("response", "response -----" + responseServer);
JSONObject jsonRootObject = new JSONObject(responseServer);
JSONArray jsonArray = jsonRootObject.optJSONArray("restaurants");
for (int i1 = 0; i1 < jsonArray.length(); i1++) {
try {
ArrayList<Group> list = new ArrayList<Group>();
ArrayList<Child> ch_list= new ArrayList<Child>();
JSONObject jsonObject = jsonArray.getJSONObject(i1);
Group gru = new Group();
JSONArray ja = jsonObject.getJSONArray("item");
Log.d("subcategory---",s_category);
gru.setName(jsonObject.getJSONArray("items").toString());
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = ja.getJSONObject(i);
Child ch = new Child();
ch.setName(jo.getString("item_name").toString());
ch_list.add(ch);
} // for loop end
gru.setItems(ch_list);
list.add(gru);
ExpAdapter = new ExpandListAdapter(
Expand.this, list);
runOnUiThread(new Runnable() {
@Override
public void run() {
ExpandList.setAdapter(ExpAdapter);}});
}
catch (JSONException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String aVoid) {
super.onPostExecute(aVoid);
}
}
Logcat error:
W/System.err: java.lang.NullPointerException
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at abservetech.com.foodapp.Expand$AsyncT1.doInBackground(Expand.java:84)
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at abservetech.com.foodapp.Expand$AsyncT1.doInBackground(Expand.java:50)
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-30 12:30:39.260 26691-26744/abservetech.com.foodapp W/System.err: at java.lang.Thread.run(Thread.java:841)