java - passing arrayList in Custom adapter -
i calling arraylist in customadapter, custom_row.xml contains desired row. want first 2 elements of arraylist side side in row, , third , fourth element in other row , on. wrote code, print first element arraylist. if remove comments , run, same error when putting comments. don't know going wrong.
or maybe should right way.
class customadapter extends arrayadapter { list<string> names; layoutinflater inflater; context context; public customadapter(context context, list<string> names) { super(context,r.layout.custom_row ,names); this.names=names; this.context=context; } @override public view getview(int position, view convertview, viewgroup parent) { inflater=layoutinflater.from(getcontext()); view customview=inflater.inflate(r.layout.custom_row,parent,false); string data=names.get(position); //string data1=names.get(position+1); textview tv=(textview)customview.findviewbyid(r.id.teama); tv.settext(data); //textview tv1=(textview)customview.findviewbyid(r.id.teamb); //tv1.settext(data1); return customview; }
i getting error- java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.textview.settext(java.lang.charsequence)' on null object reference @ com.example.customadapter.getview
the problem because tv
null, because findviewbyid(r.id.teama)
returns null, so.. check teama
exists in r.layout.custom_row