Domanda

I am currently working on an application that has a List which is populated using the LazyLoader method so I ahve the following classes:

FileCache.java, ImageLoader.java, LazyAdapter.java, Utils.java

Basically the images Load fin when I am populating the List, however I want to then show the image of the selected list item on the single item view when it is selected. So when the user clicks a list item they are taken to a new activity to see all the details around that item. To save database call I have gathered all the needed data in the list and hidden it in field and then I pass it to the single item view using the method below:

String ImageURL = ((TextView) view.findViewById(R.id.ImageURL)).getText().toString();

Intent i = new Intent(getApplicationContext(), VenueItem.class);

i.putExtra("ImageURL", ImageURL);

startActivity(i);

This then passes that URL and a bunch of other pieces of data that I am sending over to the new Activity. When it reaches the new activity I am reading that data using the method below:

String image_url;

Intent i = getIntent();

image_url = i.getStringExtra("ImageURL");

ImageView thumb_image=(ImageView) findViewById(R.id.itemImage); // thumb image

imageLoader.DisplayImage(image_url, thumb_image); //This is the line it fails on

As you can see I have highlighted the line above where it seems to fail and I get a nullpointerexception error, even though I have debugged the code and when it hits that line the 2 params it is passing are both present. The code for the image loader is below:

final int stub_id = R.drawable.noimage;
    public void DisplayImage(String url, ImageView imageView)
    {
        imageViews.put(imageView, url);
        Bitmap bitmap=memoryCache.get(url);
        if(bitmap!=null)
            imageView.setImageBitmap(bitmap);
        else
        {
            queuePhoto(url, imageView);
            imageView.setImageResource(stub_id);
        }
    }

I think this is something to do with the way I am calling the image loader maybe, can someone please help me with this as it is so annoying?? or can someone tell me of a better way to get the image already cached and displayed in the list to show on the single item activity?

Thanks

È stato utile?

Soluzione

It may sound stupid, but have you actually instantiated imageLoader? Because you haven't included the code for it ;)

It seems as though perhaps the imageLoader variable is what's null, and not the image_url and thumb_image that you're passing into it.

Trying to run

imageLoader.DisplayImage(image_url, thumb_image);

Would result in a NullPointerException if imageLoader is null e.g. you've declared it but not instantiated it:

ImageLoader imageLoader;

Which would need to be

ImageLoader imageLoader = new ImageLoader();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top