android - GridView is giving NullPointerException -
i displaying data in gridview. giving me nullpointerexception. when not display data by
oid.settext(sdata.getoid()); giving me values , not exception.
but when want display data in textview. giving me nullpointer exception.
this code:-
griddata gdata = new griddata(search.this,r.layout.griditem,r); gridview.setadapter(gdata); public class griddata extends arrayadapter<searchdata> { context context; private arraylist<searchdata> items; public griddata(context context, int textviewresourceid, arraylist<searchdata> items) { super(context, textviewresourceid, items); this.items = items; } @override public int getcount() { //return numbers of element u want on grid return items.size(); } @override public view getview(int position, view convertview, viewgroup parent) { view v; if (convertview == null) { layoutinflater vi = (layoutinflater)getsystemservice(context.layout_inflater_service); v = new view(context); v = vi.inflate(r.layout.griditem, null); } else { v = convertview; } searchdata sdata = items.get(position); system.out.println("the data "+sdata.getoid()); if(sdata != null) { textview oid = (textview) findviewbyid(r.id.oid); oid.settext(sdata.getoid()); /* textview odate = (textview) findviewbyid(r.id.odate); textview osdate = (textview) findviewbyid(r.id.osdate); textview semail = (textview) findviewbyid(r.id.semail); textview ssaddress = (textview) findviewbyid(r.id.ssaddress); textview shipzip = (textview) findviewbyid(r.id.shipzip); textview scost = (textview) findviewbyid(r.id.scost); textview noofi = (textview) findviewbyid(r.id.noofi); textview noofc = (textview) findviewbyid(r.id.noofc); textview handfee = (textview) findviewbyid(r.id.handfee); oid.settext(sdata.getoid()); /*odate.settext(sdata.getodate()); osdate.settext(sdata.getosdate()); semail.settext(sdata.getsemail()); ssaddress.settext(sdata.getssaddress()); shipzip.settext(sdata.getszip()); scost.settext(sdata.getscost()); noofi.settext(sdata.getnoofi()); noofc.settext(sdata.getnoofc()); handfee.settext(sdata.gethannlgfee());*/ } return v;} @override public searchdata getitem(int arg0) { return items.get(arg0); } @override public long getitemid(int arg0) { // todo auto-generated method stub return arg0;} }
and getitem.xml :-
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillviewport="true"> <linearlayout android:id="@+id/header" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:paddingbottom="5dip" android:paddingtop="5dip" android:orientation="horizontal"> <textview android:id="@+id/oid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/odate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/osdate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/semail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/ssaddress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/shipzip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/scost" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/noofi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/noofc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> <textview android:id="@+id/handfee" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="17dp" android:text="textview" /> </linearlayout>
05-15 15:58:48.646: e/androidruntime(2500): java.lang.nullpointerexception 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewconfiguration.get(viewconfiguration.java:332) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.view.<init>(view.java:3236) 05-15 15:58:48.646: e/androidruntime(2500): @ com.example.ship2impress.search$griddata.getview(search.java:297) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.abslistview.obtainview(abslistview.java:2271) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.gridview.onmeasure(gridview.java:1030) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.view.measure(view.java:15172) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:617) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.relativelayout.onmeasure(relativelayout.java:399) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.view.measure(view.java:15172) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4816) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.framelayout.onmeasure(framelayout.java:310) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.view.measure(view.java:15172) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.linearlayout.measurevertical(linearlayout.java:833) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.linearlayout.onmeasure(linearlayout.java:574) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.view.measure(view.java:15172) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4816) 05-15 15:58:48.646: e/androidruntime(2500): @ android.widget.framelayout.onmeasure(framelayout.java:310) 05-15 15:58:48.646: e/androidruntime(2500): @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2148) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.view.measure(view.java:15172) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1850) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1102) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1275) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1000) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4214) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.choreographer$callbackrecord.run(choreographer.java:725) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.choreographer.docallbacks(choreographer.java:555) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.choreographer.doframe(choreographer.java:525) 05-15 15:58:48.646: e/androidruntime(2500): @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:711) 05-15 15:58:48.646: e/androidruntime(2500): @ android.os.handler.handlecallback(handler.java:615) 05-15 15:58:48.646: e/androidruntime(2500): @ android.os.handler.dispatchmessage(handler.java:92) 05-15 15:58:48.646: e/androidruntime(2500): @ android.os.looper.loop(looper.java:137) 05-15 15:58:48.646: e/androidruntime(2500): @ android.app.activitythread.main(activitythread.java:4745) 05-15 15:58:48.646: e/androidruntime(2500): @ java.lang.reflect.method.invokenative(native method) 05-15 15:58:48.646: e/androidruntime(2500): @ java.lang.reflect.method.invoke(method.java:511) 05-15 15:58:48.646: e/androidruntime(2500): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 05-15 15:58:48.646: e/androidruntime(2500): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 05-15 15:58:48.646: e/androidruntime(2500): @ dalvik.system.nativestart.main(native method)
i think problem may in getitem.xml. please except me. thank timing.
change this
textview oid = (textview) findviewbyid(r.id.oid); oid.settext(sdata.getoid());
to this
textview oid = (textview) v.findviewbyid(r.id.oid); oid.settext(sdata.getoid());
Comments
Post a Comment