-2

I have an error in logcat

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference

Trying to view a picture in the list make a class for this code i think the error in the method View getView but i do not know where it is exactly i think may be here in the definition of thumbNail

public class useradaptor extends BaseAdapter {


             private Activity activity;
             private LayoutInflater inflater;
             private List<user> userItems;

ImageLoader imageLoader = AppController.getInstance().getImageLoader();

public useradaptor(Activity activity, List<user> userItems) {
    this.activity = activity;
    this.userItems = userItems;
}

@Override
public int getCount() {
    return userItems.size();
}

@Override
public Object getItem(int location) {
    return userItems.get(location);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    user u = userItems.get(position);
    if (imageLoader == null)
        imageLoader = AppController.getInstance().getImageLoader();
    NetworkImageView thumbNail = (NetworkImageView) convertView.findViewById(R.id.imageview);
    thumbNail.setImageUrl(u.getPicture(), imageLoader);

    Cache cache = AppController.getInstance().getRequestQueue().getCache();
    Cache.Entry entry = cache.get(u.getPicture());
    if(entry != null){
        try {
            String data = new String(entry.data, "UTF-8");
            // handle data, like converting it to xml, json, bitmap etc.,
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }else{
        // cached response doesn't exists. Make a network call here
    }
    return convertView;
  }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Bav
  • 139
  • 2
  • 3
  • 14

1 Answers1

1

convertView will be null if there is no row for the ListView to offer you for recycling. When convertView is null, you need to create a list row, by one means or another. Typically, you use LayoutInflater, preferably the one that you get by calling getLayoutInflater() on an Activity.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491