java - loading image from fragment in an activity FileNotFoundException error -
i want load image json file after clicking on item of list loaded file activity. show image , it's description.
it loads activity , shows image not it's description. there nthing in logcat.
east.java
@suppresslint("newapi") public class east extends fragment { listview list; textview id; textview name; button btngetdata; east adaptor; arraylist<hashmap<string, string>> oslist = new arraylist<hashmap<string, string>>(); //url json array private static string url = "http://ra.com/s/east.php"; //json node names private static final string tag_array = "coffee"; private static final string tag_id = "id"; private static final string tag_name = "name"; private static final string tag_adress = "adress"; private static final string tag_image = "image"; jsonarray coffee = null; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment return inflater.inflate(r.layout.east_fragment, container, false); } @override public void onactivitycreated(bundle savedinstancestate) { // todo auto-generated method stub super.onactivitycreated(savedinstancestate); oslist = new arraylist<hashmap<string, string>>(); btngetdata = (button)getview().findviewbyid(r.id.getdata); btngetdata.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { new jsonparse().execute(); btngetdata.setvisibility(view.gone); } }); } private class jsonparse extends asynctask<string, string, jsonobject> { private progressdialog pdialog; jsonparser jparser = new jsonparser(); private jsonobject json; @override protected void onpreexecute() { super.onpreexecute(); name = (textview)getview().findviewbyid(r.id.name); id = (textview)getview().findviewbyid(r.id.id); pdialog = new progressdialog(getactivity()); pdialog.setmessage("getting data ..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected jsonobject doinbackground(string... args) { // getting json url json = jparser.getjsonfromurl(url); return json; } @override protected void onpostexecute(jsonobject json) { pdialog.dismiss(); try { // getting json array url coffee = json.getjsonarray(tag_array); for(int = 0; < coffee.length(); i++){ jsonobject c = coffee.getjsonobject(i); // storing json item in variable string id = null; string name = null; string adress = null; string image = null; try { id = new string(c.getstring(tag_id).getbytes("iso-8859-1"), "utf8"); } catch (unsupportedencodingexception e) { // todo auto-generated catch block e.printstacktrace(); } try { name = new string(c.getstring(tag_name).getbytes("iso-8859-1"), "utf8"); } catch (unsupportedencodingexception e) { // todo auto-generated catch block e.printstacktrace(); } try { adress = new string(c.getstring(tag_adress).getbytes("iso-8859-1"), "utf8"); } catch (unsupportedencodingexception e) { // todo auto-generated catch block e.printstacktrace(); } try { image = new string(c.getstring(tag_image).getbytes("iso-8859-1"), "utf8"); } catch (unsupportedencodingexception e) { // todo auto-generated catch block e.printstacktrace(); } // adding value hashmap key => value hashmap<string, string> map = new hashmap<string, string>(); map.put(tag_id, id); map.put(tag_name, name); map.put(tag_adress, adress); map.put(tag_image, image); oslist.add(map); list = (listview)getview().findviewbyid(r.id.listview1); listadapter adapter = new simpleadapter(getactivity(), oslist, r.layout.listview, new string[] { tag_id, tag_name, tag_adress }, new int[] { r.id.id, r.id.name, r.id.adress}); list.setadapter(adapter); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent intent = new intent(getactivity(), singleitemview.class); // pass data rank intent.putextra("rank", oslist.get(+position).get("tag_id")); // pass data country intent.putextra("country", oslist.get(+position).get("tag_name")); // pass data population intent.putextra("population", oslist.get(+position).get("tag_adress")); // pass data flag intent.putextra("flag", oslist.get(+position).get("image")); // start singleitemview class startactivity(intent); } }); } } catch (jsonexception e) { e.printstacktrace(); } } } }
singleitemview.java
public class singleitemview extends activity { // declare variables string rank; string country; string population; string flag; string position; imageloader imageloader = new imageloader(this); @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // view singleitemview.xml setcontentview(r.layout.singleitemview); intent = getintent(); // result of rank rank = i.getstringextra("rank"); // result of country country = i.getstringextra("country"); // result of population population = i.getstringextra("population"); // result of flag flag = i.getstringextra("flag"); // locate textviews in singleitemview.xml textview txtrank = (textview) findviewbyid(r.id.rank); textview txtcountry = (textview) findviewbyid(r.id.country); textview txtpopulation = (textview) findviewbyid(r.id.population); // locate imageview in singleitemview.xml imageview imgflag = (imageview) findviewbyid(r.id.flag); // set results textviews txtrank.settext(rank); txtcountry.settext(country); txtpopulation.settext(population); int loader = r.drawable.loader; // capture position , set results imageview // passes flag images url imageloader.class imageloader.displayimage(flag, loader, imgflag); } }
i'm newbie , it's first app. i'll glad if give me solution solve problem.
you passing null context in east.java
Comments
Post a Comment