java - Android: Json is not able to retrieve any files from mysql database it is empty -
i new android , using mysql database linking php file connection working fine code not displaying showing background color black instead of displaying data database
public class homefragment extends fragment { gridview gv; @suppresslint("newapi") @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.home, container, false); strictmode.enabledefaults(); gv = (gridview) rootview.findviewbyid(r.id.gridview_home); getdata(); return rootview; } public void getdata(){ string result = ""; inputstream isr = null; try{ httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://192.168.1.2/android/app/getcu.php"); //your php script address httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity(); isr = entity.getcontent(); } catch(exception e){ log.e("log_tag", "error in http connection "+e.tostring()); gv.setfiltertext("couldnt connect database "+ e.getmessage()); //not printing } //convert response string try{ bufferedreader reader = new bufferedreader(new inputstreamreader(isr,"iso-8859-1"),8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } isr.close(); result=sb.tostring(); } catch(exception e){ log.e("log_tag", "error converting result "+e.tostring()); } try { string s = ""; jsonarray jarray = new jsonarray(result); for(int i=0; i<jarray.length();i++){ jsonobject json = jarray.getjsonobject(i); s = s + "name : "+json.getstring("firstname")+" "+json.getstring("lastname")+"\n"+ "age : "+json.getint("age")+"\n"+ "mobile using : "+json.getstring("mobile")+"\n\n";//+ "artist:"+json.put("images",true ); // not printing } gv.setfiltertext(s); // not printing showing empty } catch (exception e) { // todo: handle exception log.e("log_tag", "error parsing data "+e.tostring()); } } }
one more error while retrieving images folder android/pictures/image1 json not printing particular image deployed database
"artist:"+json.put("images",true );
is above statement correct retrieve images using json or have correct
please me correct above program valuable time not able understand why not printing working when extend activity how use in fragment
ok, avoid adding more comments:
Comments
Post a Comment