java - Why the data retrieved isn't shown -
i retrieve data http://api.eventful.com/rest/events/search?app_key=42t54cx7rbrdfczc&location=singapore . tag under "title", "start_time", "longitude", "latitude". not sure why couldn't display out after added longitude , latitude.
this logcat:
08-07 17:17:44.190: e/androidruntime(23734): fatal exception: main 08-07 17:17:44.190: e/androidruntime(23734): java.lang.nullpointerexception 08-07 17:17:44.190: e/androidruntime(23734): @ com.example.eventfulmaptry.mainactivity$itemadapter.getview(mainactivity.java:147) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.abslistview.obtainview(abslistview.java:1618) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.listview.measureheightofchildren(listview.java:1241) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.listview.onmeasure(listview.java:1152) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.view.measure(view.java:8513) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:3143) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1017) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.linearlayout.measurevertical(linearlayout.java:386) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.linearlayout.onmeasure(linearlayout.java:309) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.view.measure(view.java:8513) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:3143) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.framelayout.onmeasure(framelayout.java:250) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.view.measure(view.java:8513) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.linearlayout.measurevertical(linearlayout.java:531) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.linearlayout.onmeasure(linearlayout.java:309) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.view.measure(view.java:8513) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:3143) 08-07 17:17:44.190: e/androidruntime(23734): @ android.widget.framelayout.onmeasure(framelayout.java:250) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.view.measure(view.java:8513) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.viewroot.performtraversals(viewroot.java:857) 08-07 17:17:44.190: e/androidruntime(23734): @ android.view.viewroot.handlemessage(viewroot.java:1878) 08-07 17:17:44.190: e/androidruntime(23734): @ android.os.handler.dispatchmessage(handler.java:99) 08-07 17:17:44.190: e/androidruntime(23734): @ android.os.looper.loop(looper.java:130) 08-07 17:17:44.190: e/androidruntime(23734): @ android.app.activitythread.main(activitythread.java:3691) 08-07 17:17:44.190: e/androidruntime(23734): @ java.lang.reflect.method.invokenative(native method) 08-07 17:17:44.190: e/androidruntime(23734): @ java.lang.reflect.method.invoke(method.java:507) 08-07 17:17:44.190: e/androidruntime(23734): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:912) 08-07 17:17:44.190: e/androidruntime(23734): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:670) 08-07 17:17:44.190: e/androidruntime(23734): @ dalvik.system.nativestart.main(native method)
this code :
public class mainactivity extends activity { arraylist<string> title; arraylist<string> start_time; arraylist<string> latitude; arraylist<string> longitude; itemadapter adapter1; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); listview list = (listview) findviewbyid(r.id.list); title = new arraylist<string>(); latitude = new arraylist<string>(); longitude = new arraylist<string>(); try { url url = new url( "http://api.eventful.com/rest/events/search?app_key=42t54cx7rbrdfczc&location=singapore"); documentbuilderfactory dbf = documentbuilderfactory.newinstance(); documentbuilder db = dbf.newdocumentbuilder(); document doc = db.parse(new inputsource(url.openstream())); doc.getdocumentelement().normalize(); nodelist nodelist = doc.getelementsbytagname("event"); (int = 0; < nodelist.getlength(); i++) { node node = nodelist.item(i); element fstelmnt = (element) node; nodelist namelist = fstelmnt.getelementsbytagname("title"); element nameelement = (element) namelist.item(0); namelist = nameelement.getchildnodes(); title.add(""+ ((node) namelist.item(0)).getnodevalue()); nodelist websitelist = fstelmnt.getelementsbytagname("start_time"); element websiteelement = (element) websitelist.item(0); websitelist = websiteelement.getchildnodes(); start_time.add(""+ ((node) websitelist.item(0)).getnodevalue()); nodelist websitelist1 = fstelmnt.getelementsbytagname("latitude"); element websiteelement1 = (element) websitelist1.item(0); websitelist1 = websiteelement1.getchildnodes(); latitude.add(""+ ((node) websitelist1.item(0)).getnodevalue()); nodelist websitelist2 = fstelmnt.getelementsbytagname("longitude"); element websiteelement2 = (element) websitelist2.item(0); websitelist2 = websiteelement2.getchildnodes(); longitude.add(""+ ((node) websitelist2.item(0)).getnodevalue()); } } catch (exception e) { system.out.println("xml pasing excpetion = " + e); } adapter1 = new itemadapter(this); list.setadapter(adapter1); } class itemadapter extends baseadapter { final layoutinflater minflater; private class viewholder { public textview title_text; public textview des_text; public textview lat_text; public textview long_text; } public itemadapter(context context) { // todo auto-generated constructor stub super(); minflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service); } //@override public int getcount() { return title.size(); } //@override public object getitem(int position) { return position; } //@override public long getitemid(int position) { return position; } //@override public view getview(final int position, view convertview, viewgroup parent) { view view = convertview; final viewholder holder; if (convertview == null) { view = minflater.inflate(r.layout.mainpage_list,parent, false); holder = new viewholder(); holder.title_text = (textview) view.findviewbyid(r.id.title_text); holder.des_text = (textview) view.findviewbyid(r.id.des_text); holder.lat_text = (textview) view.findviewbyid(r.id.lat_text); holder.long_text = (textview) view.findviewbyid(r.id.long_text); view.settag(holder); } else { holder = (viewholder) view.gettag(); } holder.title_text.settext(""+title.get(position)); holder.des_text.settext(""+html.fromhtml(start_time.get(position))); holder.lat_text.settext(""+html.fromhtml(latitude.get(position))); holder.long_text.settext(""+html.fromhtml(longitude.get(position))); return view; } } }
listview list = (listview) findviewbyid(r.id.list); title = new arraylist<string>(); latitude = new arraylist<string>(); longitude = new arraylist<string>();
i hope forgot arraylist<string> start_time
;
so,
listview list = (listview) findviewbyid(r.id.list); title = new arraylist<string>(); latitude = new arraylist<string>(); longitude = new arraylist<string>(); start_time= new arraylist<string>(); // <-- line
Comments
Post a Comment