php - Unable to display image in listview item -


i trying image url , display listview item. url take mysql database via php.

currently not able image display in listview item.

the process using first download image , cache display on listview item. ( base on have search on web, can take direct url , display listview item).

any advise or coding great.

below code using , facing problem.

public void getproduct () {          class getjson extends asynctask<void, void, string> {             progressdialog loading;             @override             protected void onpreexecute() {                 super.onpreexecute();                 loading = progressdialog.show(getactivity(), "fetching data", "wait...", false, false);             }                         @override             protected void onpostexecute(string s) {                 super.onpostexecute(s);                 loading.dismiss();                 json_string = s;                 jsonobject jsonobject = null;                 arraylist<hashmap<string, string>> list2= new arraylist<hashmap<string, string>>();                 try {                     jsonobject = new jsonobject(json_string);                     jsonarray result = jsonobject.getjsonarray(config.tag_json_array);                     log.d("json", config.tag_json_array);                     (int = 0; < result.length(); i++) {                         jsonobject jo = result.getjsonobject(i);                         string id = jo.getstring(config.tag_id);                         string title = jo.getstring(config.tag_title);                         string brand = jo.getstring(config.tag_brand);                         string itemtype = jo.getstring(config.tag_itemtype);                         string boostertype = jo.getstring(config.tag_boostertype);                         string price = jo.getstring(config.tag_price);                         string imgurl = jo.getstring(config.tag_imgurl);                         string qtyinstock = jo.getstring(config.tag_qtyinstock);                         string qtypending = jo.getstring(config.tag_qtypending);                          hashmap<string, string> event = new hashmap<string, string>();                         event.put(config.tag_id, id);                         event.put(config.tag_title, title);                         event.put(config.tag_brand, brand);                         event.put(config.tag_itemtype, itemtype);                         event.put(config.tag_price, price);                         event.put(config.tag_imgurl, imgurl);                         event.put(config.tag_qtyinstock, qtyinstock);                         event.put(config.tag_qtypending, qtypending);  //the code added picasso                          imageview img = (imageview)getactivity().findviewbyid(r.id.iv_flag);                     string imgurl = (string)event.get(config.tag_imgurl);                     picasso.with(getactivity()).load(imgurl).into(img);                             list2.add(event);                             listadapter adapter = new myadapter(                                             getactivity().getbasecontext(), list2, r.layout.productitem,                                             new string[]{config.tag_title, config.tag_price, config.tag_brand, config.tag_itemtype, config.tag_qtyinstock, "flag"},                                             new int[]{r.id.text1, r.id.text2, r.id.text3, r.id.text4, r.id.text5, r.id.iv_flag});                             productlisting.setadapter(adapter);                             hashmap<string, object> hm = (hashmap<string, object>)adapter.getitem(i);                             string imgurl = (string)event.get(config.tag_imgurl);                             imageloadertask imageloadertask = new imageloadertask();                             hashmap<string, object> hmdownload = new hashmap<string, object>();                             hm.put("flag_path", imgurl);                             hm.put("position",i);                             imageloadertask.execute(hm);                         }                     } catch (jsonexception e) {                         log.e("json parser", "error parsing data [" + e.getmessage() + "] " + jsonobject);                         e.printstacktrace();                     }                 }                  @override                 protected string doinbackground(void... params) {                     requesthandler rh = new requesthandler();                                     string s = rh.sendgetrequest("the url php file");                     return s;                 }             }             final getjson gj = new getjson();             gj.execute();         }         /** asynctask download , load image in listview */         private class imageloadertask extends asynctask<hashmap<string, object>, void, hashmap<string, object>>{             @override             protected hashmap<string, object> doinbackground(hashmap<string, object>... hm) {                 inputstream istream=null;                 string imgurl = (string) hm[0].get("flag_path");                 log.d("url1", imgurl);                 int position = (integer) hm[0].get("position");                 url url;                 try {                     url = new url(imgurl);                     // creating http connection communicate url                     httpurlconnection urlconnection = (httpurlconnection) url.openconnection();                     // connecting url                     urlconnection.connect();                     // reading data url                     istream = urlconnection.getinputstream();                     // getting caching directory                     file cachedirectory = getactivity().getbasecontext().getcachedir();                     // temporary file store downloaded image                     file tmpfile = new file(cachedirectory.getpath() + "/wpta_"+position+".png");                     // fileoutputstream temporary file                     fileoutputstream foutstream = new fileoutputstream(tmpfile);                     // creating bitmap downloaded inputstream                     bitmap b = bitmapfactory.decodestream(istream);                     // writing bitmap temporary file png file                     b.compress(bitmap.compressformat.png,100, foutstream);                     // flush fileoutputstream                     foutstream.flush();                     //close fileoutputstream                     foutstream.close();                     // create hashmap object store image path , position in listview                     hashmap<string, object> hmbitmap = new hashmap<string, object>();                     // storing path temporary image file                     hmbitmap.put("flag",tmpfile.getpath());                     // storing position of image in listview                     hmbitmap.put("position",position);                     // returning hashmap object containing image path , position                     return hmbitmap;                  }catch (exception e) {                     e.printstacktrace();                 }                 return null;             }              @override             protected void onpostexecute(hashmap<string, object> result) {                 // getting path downloaded image                 string path = (string) result.get("flag");                 // getting position of downloaded image                 int position = (integer) result.get("position");                 // getting adapter of listview                 simpleadapter adapter = (simpleadapter)productlisting.getadapter();                 // getting hashmap object @ specified position of listview                 hashmap<string, object> hm = (hashmap<string, object>) adapter.getitem(position);                 // overwriting existing path in adapter                 hm.put("flag",path);                 // noticing listview dataset changes                 adapter.notifydatasetchanged();             }         } 

the logcat:

06-11 19:16:21.621 21935-22767/info.androidhive.slidingmenu d/url1: http://www.genesisfrontier.com/cfs/files/images/ib53zanjknpj2cqcs/bfeh_eb2.png 06-11 19:16:21.621 21935-22767/info.androidhive.slidingmenu i/system.out: (httplog)-static: issbsettingenabled false 06-11 19:16:21.631 21935-22767/info.androidhive.slidingmenu i/system.out: knoxvpnuidstorageknoxvpnsupported api value returned false 06-11 19:16:21.731 21935-21935/info.androidhive.slidingmenu e/bitmapfactory: unable decode stream: java.io.filenotfoundexception: : open failed: enoent (no such file or directory) 06-11 19:16:21.731 21935-21935/info.androidhive.slidingmenu i/system.out: resolveuri failed on bad bitmap uri:  

below logcat picasso

fatal exception: main                                                                             process: info.androidhive.slidingmenu, pid: 1289                                                                             java.lang.illegalargumentexception: target must not null.                                                                                 @ com.squareup.picasso.requestcreator.into(requestcreator.java:618)                                                                                 @ com.squareup.picasso.requestcreator.into(requestcreator.java:601)                                                                                 @ info.androidhive.slidingmenu.findpeoplefragment$1getjson.onpostexecute(findpeoplefragment.java:147)                                                                                 @ info.androidhive.slidingmenu.findpeoplefragment$1getjson.onpostexecute(findpeoplefragment.java:91)                                                                                 @ android.os.asynctask.finish(asynctask.java:632)                                                                                 @ android.os.asynctask.access$600(asynctask.java:177)                                                                                 @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:645)                                                                                 @ android.os.handler.dispatchmessage(handler.java:102)                                                                                 @ android.os.looper.loop(looper.java:145)                                                                                 @ android.app.activitythread.main(activitythread.java:5938)                                                                                 @ java.lang.reflect.method.invoke(native method)                                                                                 @ java.lang.reflect.method.invoke(method.java:372)                                                                                 @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1389)                                                                                 @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1184) 

use picasso lib download image url automatically download image url. use picasso library add in gradle file

compile 'com.squareup.picasso:picasso:2.5.2' 

and this

string imgurl = (string)event.get(config.tag_imgurl); picasso.with(context).load(imgurl).into("your imageview"); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -