java - How do I solve NullPointerException in CustomList -
this customlist
class
customlist:
public class customlist extends arrayadapter<string> { private final activity context; private final string[] web; private final integer[] imageid; public customlist(activity context,string[] web, integer[] imageid) { super(context, r.layout.single_row, web); this.context = context; this.web = web; this.imageid = imageid; } @override public view getview(int position, view view, viewgroup parent) { layoutinflater inflater = context.getlayoutinflater(); view rowview= inflater.inflate(r.layout.single_row, null, true); textview txttitle = (textview) rowview.findviewbyid(r.id.txt); imageview imageview = (imageview) rowview.findviewbyid(r.id.img); txttitle.settext(web[position]); imageview.setimageresource(imageid[position]); return rowview; } }
and imageid
array fill while
loop below
while(crs.movetonext()){ string img = crs.getstring(crs.getcolumnindex("icon")); try { imageid[i] = integer.parseint(img); } catch(numberformatexception nfe) {} i++; }
but when run see error in customlist
error on line after end of class
imageview.setimageresource(imageid[position]);
logcat :
2021-2021/com.exercise.androidhtml e/androidruntime﹕ fatal exception: main java.lang.nullpointerexception @ com.exercise.androidhtml.customlist.getview(customlist.java:35) @ android.widget.abslistview.obtainview(abslistview.java:2177) @ android.widget.listview.measureheightofchildren(listview.java:1247) @ android.widget.listview.onmeasure(listview.java:1159) @ android.view.view.measure(view.java:15848) @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:728) @ android.widget.relativelayout.onmeasure(relativelayout.java:477) @ android.view.view.measure(view.java:15848) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5012) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.view.view.measure(view.java:15848) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5012) @ com.android.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:302) @ android.view.view.measure(view.java:15848) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5012) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2189) @ android.view.view.measure(view.java:15848) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1905) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1104) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1284) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1004) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5481) @ android.view.choreographer$callbackrecord.run(choreographer.java:749) @ android.view.choreographer.docallbacks(choreographer.java:562) @ android.view.choreographer.doframe(choreographer.java:532) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:735) @ android.os.handler.handlecallback(handler.java:730) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5103) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) @ dalvik.system.nativestart.main(native method)
it seems imageview
or imageid
null
. please, double check you're setting imageid
value, , single_row
layout has imageview
img
id.
Comments
Post a Comment