android - java.lang.NullPointerException: Attempt to invoke virtual method' on a null object reference -


this question has answer here:

i tried see every answer question did not work me

i know counter view return null don not know why

tried in code did not worked

      public view getview(int position, view convertview, viewgroup parent) {     // todo auto-generated method stub        layoutinflater inflater=activity.getlayoutinflater();      if(convertview == null){          convertview=inflater.inflate(r.layout.column_row, null);          txtfirst=(textview) convertview.findviewbyid(r.id.name);         txtsecond=(textview) convertview.findviewbyid(r.id.gender);         txtthird=(textview) convertview.findviewbyid(r.id.age);         //txtfourth=(textview) convertview.findviewbyid(r.id.status);          if (txtfirst == null) {             txtfirst.settext("kkkk");         }         if (txtsecond == null) {             txtsecond.settext("kllll");         }         if (txtthird == null) {             txtthird.settext("llllll");         }      }     return convertview;    } 

my logcat

caused by: java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.listview.setadapter(android.widget.listadapter)' on null object reference 

my code

package com.example.bavly.dollorvalueindifferentboanksegypt;    import android.app.activity; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.textview;  import java.util.arraylist; import java.util.hashmap;  import static       com.example.bavly.dollorvalueindifferentboanksegypt.constants.first_column; import static    com.example.bavly.dollorvalueindifferentboanksegypt.constants.second_column; import static    com.example.bavly.dollorvalueindifferentboanksegypt.constants.third_column;  public class listviewadapters extends baseadapter { public arraylist<hashmap<string, string>> list; activity activity; textview txtfirst; textview txtsecond; textview txtthird; //textview txtfourth; public listviewadapters(activity activity,arraylist<hashmap<string, string>> list){     super();     this.activity=activity;     this.list=list; }  @override public int getcount() {     // todo auto-generated method stub     return list.size(); }  @override public object getitem(int position) {     // todo auto-generated method stub     return list.get(position); }  @override public long getitemid(int position) {     // todo auto-generated method stub     return 0; }    @override public view getview(int position, view convertview, viewgroup parent) {     // todo auto-generated method stub        layoutinflater inflater=activity.getlayoutinflater();      if(convertview == null){          convertview=inflater.inflate(r.layout.column_row, null);          txtfirst=(textview) convertview.findviewbyid(r.id.name);         txtsecond=(textview) convertview.findviewbyid(r.id.gender);         txtthird=(textview) convertview.findviewbyid(r.id.age);         //txtfourth=(textview) convertview.findviewbyid(r.id.status);       }      hashmap<string, string> map=list.get(position);     txtfirst.settext(map.get(first_column));     txtsecond.settext(map.get(second_column));     txtthird.settext(map.get(third_column));     //txtfourth.settext(map.get(fourth_column));      return convertview; }  } 

the listview null. confirm findviewbyid doesn't return null.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -