android - NullPointerException in getView Of Adapter extends BaseAdapter -
i populating listview search in tabwidget.my list contain image , textview.without tabwidget works fines in tabwidget gives error .i have error in getview locat is
08-07 16:24:44.300: e/androidruntime(20166): fatal exception: main 08-07 16:24:44.300: e/androidruntime(20166): java.lang.nullpointerexception 08-07 16:24:44.300: e/androidruntime(20166): @ com.example.project.searchdictionaryactivity$mycustomadapter.getview(searchdictionaryactivity.java:392) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.abslistview.obtainview(abslistview.java:2485) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.listview.measureheightofchildren(listview.java:1250) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.listview.onmeasure(listview.java:1161) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1385) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurevertical(linearlayout.java:670) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.onmeasure(linearlayout.java:563) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.framelayout.onmeasure(framelayout.java:293) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1385) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurevertical(linearlayout.java:670) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.onmeasure(linearlayout.java:563) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.framelayout.onmeasure(framelayout.java:293) 08-07 16:24:44.300: e/androidruntime(20166): @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2242) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.framelayout.onmeasure(framelayout.java:293) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1385) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurevertical(linearlayout.java:670) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.onmeasure(linearlayout.java:563) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.framelayout.onmeasure(framelayout.java:293) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.framelayout.onmeasure(framelayout.java:293) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1385) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.measurevertical(linearlayout.java:670) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.linearlayout.onmeasure(linearlayout.java:563) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4712) 08-07 16:24:44.300: e/androidruntime(20166): @ android.widget.framelayout.onmeasure(framelayout.java:293) 08-07 16:24:44.300: e/androidruntime(20166): @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2242) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.view.measure(view.java:12842) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1240) 08-07 16:24:44.300: e/androidruntime(20166): @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2632) 08-07 16:24:44.300: e/androidruntime(20166): @ android.os.handler.dispatchmessage(handler.java:99) 08-07 16:24:44.300: e/androidruntime(20166): @ android.os.looper.loop(looper.java:137) 08-07 16:24:44.300: e/androidruntime(20166): @ android.app.activitythread.main(activitythread.java:4517) 08-07 16:24:44.300: e/androidruntime(20166): @ java.lang.reflect.method.invokenative(native method) 08-07 16:24:44.300: e/androidruntime(20166): @ java.lang.reflect.method.invoke(method.java:511) 08-07 16:24:44.300: e/androidruntime(20166): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:993) 08-07 16:24:44.300: e/androidruntime(20166): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:760) 08-07 16:24:44.300: e/androidruntime(20166): @ dalvik.system.nativestart.main(native method)
my search_dictionary_item_item.xml is
<?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="wrap_content" android:gravity="left|center" android:paddingbottom="5dp" android:paddingleft="5dp" android:paddingtop="10dp" > <imageview android:id="@+id/imageview01" android:layout_width="50dp" android:layout_height="60dp" > </imageview> <textview android:id="@+id/textview01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:textcolor="#0099cc" android:textsize="20dp" android:textstyle="bold" > </textview> </linearlayout>
my line 392 is
at com.example.project.searchdictionaryactivity$mycustomadapter.getview(searchdictionaryactivity.java:392)
is
textview textview = (textview) row.findviewbyid(r.id.textview01);
i have tried 2 suggestion
1.
public view getview(int position, view convertview, viewgroup parent) { view row=convertview; context c = null; if(convertview==null){ layoutinflater inflater = getlayoutinflater(null); row = inflater.inflate(r.layout.search_dictionary_item_item, parent, false); } textview textview = (textview) row.findviewbyid(r.id.textview01); imageview imageview = (imageview) row.findviewbyid(r.id.imageview01); textview.settext(data_text[position]); imageview.setimagebitmap(data_image[position]); return (row); }
for placing null getlayoutinflater(null); get
the method getlayoutinflater() in type activity not applicable arguments (null)
2.sugesstion
public view getview(int position, view convertview, viewgroup parent) { // layoutinflater inflater = getlayoutinflater(); view row; layoutinflater inflater = (layoutinflater) convertview.getcontext().getsystemservice( context.layout_inflater_service ); row = inflater.inflate(r.layout.search_dictionary_item_item, parent, false); textview textview = (textview) row.findviewbyid(r.id.textview01); imageview imageview = (imageview) row.findviewbyid(r.id.imageview01); textview.settext(data_text[position]); imageview.setimagebitmap(data_image[position]); return (row); }
both doesnot work logcat given above
try link custom adapter here
Comments
Post a Comment