java - SetAdapter for arrayadapter is crashing -
my app keeps crashing whenever setadapter function gets called , have no idea why, can help? emulator running says app has stopped unexpectedly.
this main
public class mainactivity extends activity { private listview listview1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); ride ride_data[] = new ride[] { new ride("la trip", "la man"), new ride("sd trip", "sd man"), new ride("sf trip", "sf man") }; rideadapter adapter = new rideadapter(this, r.layout.listview_item_row,ride_data); listview1 = (listview)findviewbyid(r.id.listview1); view header = (view)getlayoutinflater().inflate(r.layout.listview_header_row, null); listview1.addheaderview(header); listview1.setadapter(adapter); } }
and adapter
public class rideadapter extends arrayadapter<ride>{ context context; int layoutresourceid; ride data[] = null; public rideadapter(context context, int layoutresourceid, ride[] data) { super(context,layoutresourceid,data); this.context = context; this.layoutresourceid = layoutresourceid; this.data = data; } @override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; rideholder holder = null; if(row == null) { layoutinflater inflater = ((activity)context).getlayoutinflater(); row = inflater.inflate(layoutresourceid, parent, false); holder = new rideholder(); holder.ridename = (textview)row.findviewbyid(r.id.txtridename); holder.personname = (textview)row.findviewbyid(r.id.txtpersonname); row.settag(holder); } else { holder = (rideholder)row.gettag(); } ride ride = data[position]; holder.ridename.settext(ride.ridename); holder.personname.settext(ride.personname); return row; } public static class rideholder { textview ridename; textview personname; } }
this ride class
public class ride { public string ridename; public string personname; public ride() { } public ride(string ridename, string personname) { super(); this.ridename=ridename; this.personname=personname; } }
and list item view
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp" > <textview android:id="@+id/txtridename" android:layout_width ="wrap_content" android:layout_height="fill_parent" android:gravity="center_horizontal" /> <textview android:id="@+id/txtpersonname" android:layout_width ="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" /> </linearlayout>
any appreciated!
<textview android:id="@+id/txtridename" android:layout_width ="wrap_content" android:layout_height="fill_parent" android:gravity="center_horizontal" /> <textview android:id="@+id/txtpersonname" android:layout_width ="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" />
textview should textview not textview.
you should learn read crash in logcat.
android.view.inflateexception: binary xml file line #8: error inflating class textview
05-03 11:18:29.399: e/androidruntime(12890): fatal exception: main 05-03 11:18:29.399: e/androidruntime(12890): android.view.inflateexception: binary xml file line #8: error inflating class textview 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:698) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.rinflate(layoutinflater.java:746) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-03 11:18:29.399: e/androidruntime(12890): @ com.example.hello1.rideadapter.getview(rideadapter.java:30) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.headerviewlistadapter.getview(headerviewlistadapter.java:220) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.abslistview.obtainview(abslistview.java:2468) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.listview.makeandaddview(listview.java:1775) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.listview.filldown(listview.java:678) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.listview.fillfromtop(listview.java:739) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.listview.layoutchildren(listview.java:1628) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.abslistview.onlayout(abslistview.java:2303) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.view.layout(view.java:14063) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewgroup.layout(viewgroup.java:4655) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.relativelayout.onlayout(relativelayout.java:948) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.view.layout(view.java:14063) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewgroup.layout(viewgroup.java:4655) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.framelayout.onlayout(framelayout.java:448) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.view.layout(view.java:14063) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewgroup.layout(viewgroup.java:4655) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.linearlayout.setchildframe(linearlayout.java:1655) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.linearlayout.layoutvertical(linearlayout.java:1513) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.linearlayout.onlayout(linearlayout.java:1426) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.view.layout(view.java:14063) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewgroup.layout(viewgroup.java:4655) 05-03 11:18:29.399: e/androidruntime(12890): @ android.widget.framelayout.onlayout(framelayout.java:448) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.view.layout(view.java:14063) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewgroup.layout(viewgroup.java:4655) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2017) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1838) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1131) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4611) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.choreographer$callbackrecord.run(choreographer.java:725) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.choreographer.docallbacks(choreographer.java:555) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.choreographer.doframe(choreographer.java:525) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:711) 05-03 11:18:29.399: e/androidruntime(12890): @ android.os.handler.handlecallback(handler.java:615) 05-03 11:18:29.399: e/androidruntime(12890): @ android.os.handler.dispatchmessage(handler.java:92) 05-03 11:18:29.399: e/androidruntime(12890): @ android.os.looper.loop(looper.java:137) 05-03 11:18:29.399: e/androidruntime(12890): @ android.app.activitythread.main(activitythread.java:4898) 05-03 11:18:29.399: e/androidruntime(12890): @ java.lang.reflect.method.invokenative(native method) 05-03 11:18:29.399: e/androidruntime(12890): @ java.lang.reflect.method.invoke(method.java:511) 05-03 11:18:29.399: e/androidruntime(12890): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1008) 05-03 11:18:29.399: e/androidruntime(12890): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:775) 05-03 11:18:29.399: e/androidruntime(12890): @ dalvik.system.nativestart.main(native method) 05-03 11:18:29.399: e/androidruntime(12890): caused by: java.lang.classnotfoundexception: android.view.textview 05-03 11:18:29.399: e/androidruntime(12890): @ dalvik.system.basedexclassloader.findclass(basedexclassloader.java:61) 05-03 11:18:29.399: e/androidruntime(12890): @ java.lang.classloader.loadclass(classloader.java:501) 05-03 11:18:29.399: e/androidruntime(12890): @ java.lang.classloader.loadclass(classloader.java:461) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.createview(layoutinflater.java:552) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.oncreateview(layoutinflater.java:643) 05-03 11:18:29.399: e/androidruntime(12890): @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:66) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.oncreateview(layoutinflater.java:660) 05-03 11:18:29.399: e/androidruntime(12890): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:685)
Comments
Post a Comment