hectichavana
hectichavana

Reputation: 1446

Android: Nullpointer Exception Error in Activity

I have this getView method inside my ListViewAdapter:

public static class ViewHolder{
        public TextView textTitle;
        public ImageView image;
    }

  public View getView(int position, View convertView, ViewGroup parent)
    {
        Project pro = getItem(position);
        
        View vi=convertView;
        ViewHolder holder;
        if(convertView==null){
            vi = inflater.inflate(R.layout.listitems, null);
            holder=new ViewHolder();
            holder.textTitle=(TextView)vi.findViewById(R.id.txt_title);;
            holder.image=(ImageView)vi.findViewById(R.id.image);
            vi.setTag(holder);
        }
        else
        holder=(ViewHolder)vi.getTag();
        holder.textTitle.setText(pro.project_title);
        holder.image.setTag(pro);
        imageLoader.DisplayImage(pro.smallImageUrl, activity, holder.image);
        return vi;

    }

Since this is for a listview, it shows both images and text. In the other hand I have an activity, where I want to apply the imageLoader.DisplayImage method in it only to show images.

Based on the ListView Adapter, I made this inside an activity:

imageLazy(image1, Main.this, prjcts.get(randomIndex1));

public void imageLazy(final ImageView image, Activity activity, Project pro)
    {
    imageLoaderx.DisplayImage(pro.smallImageUrl, activity, image);
    }

But then my app crashed. The Logcat reports a Nullpointer Exception Error and an error with my imageLazy method.

How can I solve my problem, so that my method can display the images without error?

Upvotes: 0

Views: 823

Answers (1)

Mike dg
Mike dg

Reputation: 4658

imageLoaderX has not been initialized and is null. You can fix this by creating a new object or getting a non null reference elsewhere.

Upvotes: 1

Related Questions