json - Connection issues in android, stream returning null -
i trying data database
listview
. have used json
parsing that. when run servlet
correct parsed value. m trying make connection not coming off
dbmapping
public class mysearch extends activity { class event_location{ string place; string area; int cost2; int cost2wa; int uid; @override public string tostring() { return "venue details [place=" + place +", area=" + area + ", cost2=" + cost2 + ", cost2wa = "+ cost2wa +"]"; } } class fetchcollegedetailstask extends asynctask<void, void, inputstream> { @override protected inputstream doinbackground(void... arg0) { log.e("testing @@@@@@" ,"test connnection" + "" ); //192.168.1.102:8080/first/myservlet //string stringurl="http://www.google.com"; string stringurl="http://192.168.1.102:8080/first/myservlet"; url url; try { url = new url(stringurl); log.e("url data test " , ""+ url); //log.e("test"+ url.openconnection().getinputstream() , ""); log.e("hiii", "hiii"); //log.e("input",""+url.openconnection().getinputstream() ); // return url.openconnection().getinputstream(); urlconnection connection = url.openconnection(); log.e("test" ,""+ connection);
after above line nothing taking place::
inputstream stream = connection.getinputstream(); log.e("stream" ,""+ stream); //string test = url.openconnection().getinputstream(); return stream; } catch (malformedurlexception e) { log.e("amit", "search"); // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return null; } @override protected void onpostexecute(inputstream result) { super.onpostexecute(result); log.e("result", ""+result); stringbuilder builder = new stringbuilder(); bufferedreader reader = new bufferedreader(new inputstreamreader(result)); string line = null; try { while((line = reader.readline()) != null) { builder.append(line); } } catch (ioexception e) { e.printstacktrace(); } string jsonstring = builder.tostring(); log.e("getcoursesactivity", jsonstring); try { jsonobject rootobject = new jsonobject(jsonstring); jsonarray jsonarray = rootobject.getjsonarray("event_locations"); (int index = 0; index < jsonarray.length(); index++) { jsonobject object = (jsonobject) jsonarray.get(index); event_location detail = new event_location(); detail.place = object.getstring("place"); detail.area = object.getstring("area"); detail.cost2 = object.getint("cost_for_2"); detail.cost2wa = object.getint("cost_for_2_wa"); array.add(detail); } } catch (jsonexception e) { e.printstacktrace(); } adapter.notifydatasetchanged(); } } private arraylist<event_location> array; private arrayadapter<event_location> adapter; private listview listview; @override protected void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.search); array = new arraylist<event_location>(); log.e("array"+ array ,""); listview = (listview) findviewbyid(r.id.listview); adapter = new arrayadapter<event_location>(this, android.r.layout.simple_expandable_list_item_1,array); // adapter = new arrayadapter<event_location>(this, android.r.layout.simple_list_item_1, array); listview.setadapter(adapter); } @suppresslint("newapi") @override public boolean onoptionsitemselected(menuitem item) { log.e("test","test"); if (item.gettitle().equals("parse")) { strictmode.setthreadpolicy(new strictmode.threadpolicy.builder().detectnetwork().detectall().build()); new fetchcollegedetailstask().execute(); } return super.onoptionsitemselected(item); }
data should come listview
after clicking on parse option in menu
@override public boolean oncreateoptionsmenu(menu menu) { menu.add("parse"); return true; } }
Comments
Post a Comment