android - null pointer exception for custonlistadapter? -
public class listpage extends listactivity { thelists a[] = new thelists[1]; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.list_page); setlistadapter(new myadapter()); } @override protected void onlistitemclick(listview l, view v, int position, long id) { class myadapter extends arrayadapter<thelists> { myadapter() { super(listpage.this, r.layout.list_row, r.id.sname, a); } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = getlayoutinflater(); view row = inflater.inflate(r.layout.list_row,parent,false); textview name,category,id; name=(textview)row.findviewbyid(r.id.sname); category=(textview)row.findviewbyid(r.id.scategory); id=(textview)row.findviewbyid(r.id.sid); name.settext(a[0].schemelist[position]); category.settext(a[0].categorylist[position]); id.settext(a[0].idlist[position]); return(row); } } } }
i'm getting runtime error says
05-02 18:56:32.224: e/androidruntime(775): fatal exception: main 05-02 18:56:32.224: e/androidruntime(775): java.lang.nullpointerexception 05-02 18:56:32.224: e/androidruntime(775): @ com.example.listinflator_demo.listpage$myadapter.getview(listpage.java:75) 05-02 18:56:32.224: e/androidruntime(775): @ android.widget.abslistview.obtainview(abslistview.java:2159)
what changes needed ?
in constructor, there strange :
you pass parameter super. isn't initialized, never. value ?
anyhow, suggest understand better want null pointer exception means. meet kind of error quite when programming in java, better understanding how find , correct them yourself, it's more interesting getting question answered.
Comments
Post a Comment