i am using a listview with baseadapter and on scroll of the listview it crashes.
My getView
method of the BaseAdapter
class
@Override
public View getView(final int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
LayoutInflater inflater = activity.getLayoutInflater();
ViewHolder holder=null;
if(arg1 == null){
//Login category
if(categoryList.get(arg0).getType()==1){
arg1 = inflater.inflate(R.layout.switch_profile_header, null);
holder=new ViewHolder();
holder.layout=(RelativeLayout)arg1.findViewById(R.id.switch_profile_header_view);
holder.categoryName =(TextView)arg1.findViewById(R.id.categoryName);
holder.isLogin=categoryList.get(arg0).getIsLogin();
arg1.setTag(holder);
}
//Other category
else if(categoryList.get(arg0).getType()==0){
arg1 = inflater.inflate(R.layout.switch_profile_listrow, null);
holder=new ViewHolder();
holder.layout=(RelativeLayout)arg1.findViewById(R.id.switch_profile_listrow_view);
holder.categoryName =(TextView)arg1.findViewById(R.id.categoryName);
holder.isLogin=categoryList.get(arg0).getIsLogin();
holder.isDelete=(ImageView)arg1.findViewById(R.id.categoryDelete);
holder.login=(ImageView)arg1.findViewById(R.id.categoryLogin);
arg1.setTag(holder);
}
}else {
holder = (ViewHolder) arg1.getTag();
}
//Login category
if(categoryList.get(arg0).getType()==1){
holder.categoryName.setText(Html.fromHtml(categoryList.get(arg0).getCategoryName()));
holder.layout.setBackgroundColor(Color.parseColor("#efefef"));
}
//Login category
else if(categoryList.get(arg0).getType()==0){
if(flag==false){
holder.isDelete.setVisibility(View.INVISIBLE);
}else{
holder.isDelete.setVisibility(View.VISIBLE);
}
if(categoryList.get(arg0).getIsLogin().equalsIgnoreCase("1")){
holder.isDelete.setVisibility(View.INVISIBLE);
holder.login.setVisibility(View.INVISIBLE);
}else if(flag) {
holder.isDelete.setVisibility(View.VISIBLE);
holder.login.setVisibility(View.VISIBLE);
}
holder.categoryName.setText(Html.fromHtml(categoryList.get(arg0).getCategoryName()));
if(categoryList.get(arg0).getIsLogin().equalsIgnoreCase("1")){
holder.layout.setBackgroundColor(Color.parseColor("#efefef"));
}else{
holder.layout.setBackgroundColor(Color.parseColor("#f0f0f0"));
}
return arg1;
}
My Logcat
Process: com.Tiger.Tiger, PID: 14059
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setVisibility(int)' on a null object reference
at com.TenderTiger.Adapter.SwitchProfileAdapter.getView(SwitchProfileAdapter.java:117)
at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
at android.widget.AbsListView.obtainView(AbsListView.java:2344)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.correctTooLow(ListView.java:1474)