json - list view did not show any value in android studio -
currently i'm try develop project using php , android studio. i'm using list view. have google other tutorial did not found answer , still have problem using list view.
05-30 23:10:15.592 7820-7849/com.example.ayim.madoc d/all products:﹕ {"success":1,"patient":[{"id":"1","name":"ikhwan johari"},{"id":"2","name":"ruminah bedah"},{"id":"3","name":"kamal sado"}]} 05-30 23:10:15.592 7820-7849/com.example.ayim.madoc w/system.err﹕ org.json.jsonexception: no value idpatient 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ org.json.jsonobject.get(jsonobject.java:354) 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ org.json.jsonobject.getstring(jsonobject.java:510) 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ com.example.ayim.madoc.listpatient$loadallpatient.doinbackground(listpatient.java:112) 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ com.example.ayim.madoc.listpatient$loadallpatient.doinbackground(listpatient.java:69) 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ android.os.asynctask$2.call(asynctask.java:287) 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ java.util.concurrent.futuretask.run(futuretask.java:234) 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 05-30 23:10:15.593 7820-7849/com.example.ayim.madoc w/system.err﹕ @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 05-30 23:10:15.594 7820-7849/com.example.ayim.madoc w/system.err﹕ @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 05-30 23:10:15.594 7820-7849/com.example.ayim.madoc w/system.err﹕ @ java.lang.thread.run(thread.java:838) here stack shows. value database fetch did not display in list view. don't know how fixed this. can me?
im still new in android studio. thank you.
here code in java.
public class listpatient extends listactivity { //string intentid = getintent().getextras().getstring("id"); // progress dialog private progressdialog pdialog; // creating json parser object jsonparser jparser = new jsonparser(); arraylist<hashmap<string, string>> patientlist; jsonarray patient = null; textview idshow; private static final string list_url = "http://104.223.3.210/madoc/all_patient.php"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_list_patient); idshow = (textview) findviewbyid(r.id.id); idshow.settext(getintent().getextras().getstring("id")); // hashmap listview patientlist = new arraylist<hashmap<string, string>>(); // loading products in background thread new loadallpatient().execute(); // listview listview lv = getlistview(); } class loadallpatient extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(listpatient.this); pdialog.setmessage("loading products. please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } @override protected string doinbackground(string... params) { try { list<namevaluepair> paras = new arraylist<namevaluepair>(); // getting json string url paras.add(new basicnamevaluepair("id", getintent().getextras().getstring("id"))); jsonobject json1 = jparser.makehttprequest(list_url, "post", paras); log.d("all products: ", json1.tostring()); // checking success tag int success = json1.getint("success"); if (success == 1) { patient = json1.getjsonarray("patient"); // looping through products (int = 0; < patient.length(); i++) { jsonobject c = patient.getjsonobject(i); // storing each json item in variable string id = c.getstring("idpatient"); string name = c.getstring("name"); // creating new hashmap hashmap<string, string> map = new hashmap<string, string>(); // adding each child node hashmap key => value map.put("id", id); map.put("name", name); // adding hashlist arraylist patientlist.add(map); } } else { idshow.settext("no patient"); } } catch (jsonexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { // dismiss dialog after getting products pdialog.dismiss(); // updating ui background thread runonuithread(new runnable() { public void run() { /** * updating parsed json data listview * */ listadapter adapter = new simpleadapter( listpatient.this, patientlist, r.layout.list_patient, new string[] { "id", "name"}, new int[] { r.id.id, r.id.name }); // updating listview setlistadapter(adapter); } }); } } }
exception thrown here:
string id = c.getstring("idpatient"); there no "idpatient" key in json. try replace "id"
Comments
Post a Comment