0

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?

3
  • 1
    Look carefully at your exception stack trace. There should be the number of line in your code where exception has occured. Debug that part of code and find what is null and think why. Commented May 6, 2011 at 13:18
  • I know, here's the error: imageLoaderx.DisplayImage(pro.smallImageUrl, activity, image) but I can't solve it Commented May 6, 2011 at 13:19
  • 2
    just start debugging, go to the line and find out, which variable in that line is null or which method returns null and than find out why. Thats the basics that should be done when you got a null pointer exception Commented May 6, 2011 at 13:21

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

oh that I have already initialized as a global variable: public ImageLoader imageLoaderx; that should be correct right?
You need to actually set it though. Either imageLoaderx = new ImageLoader() or imageLoaderx = someotherimageloderreference;
I set it like this: ImageLoader imageLoaderx = new ImageLoader(Main.this); still gives me an error :(
maybe pro is null when passed into that method?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.