Search code examples
androidandroid-studioandroid-gradle-pluginuniversal-image-loader

UniversalImageLoader null crash


I had an issue where I ran out of storage on my MacBook, and upon returning to my Android project after deleting some files (unrelated to Android), I am now getting errors with libraries.

This is the error I receive:

E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab8161a0 01-28

E/libEGL: call to OpenGL ES API with no current context (logged once per thread)

E/ImageLoader: null

Here's the relevant code:

@Override
public void onBindViewHolder(final AttractionRowViewHolder attractionRowViewHolder, int position) {
    ImageLoader imageLoader;
    imageLoader = ImageLoader.getInstance();

    Bitmap imageTest = imageLoader.loadImageSync(currentAttraction.attractionImageSmall, options);
    Bitmap image = ImageHelper.scaleCenterCrop(imageTest, 156, 156); //Twice size of image view to retain resolution
    image = ImageHelper.getRoundCornerBitmap(image, 14); //Twice actual scaled down corner radius
    attractionRowViewHolder.imageView.setImageBitmap(image);
}

It's crashing on this line:

    Bitmap imageTest = imageLoader.loadImageSync(currentAttraction.attractionImageSmall, options);

I have tried doing a gradle sync, a rebuild, renaming .jar file etc. but nothing has worked so far.

Anyone have any ideas? I assume something was deleted automatically when I ran out of capacity.

EDIT:

It turns out that it's the line below that crashes. imageTest is null, and scaleCenterCrop cannot take a null. I still don't know why it is null all of a sudden though?


Solution

  • I'd guess that the bitmap's not loaded yet since you don't put it in an AsyncTask.

    Why don't you do this instead?

    imageLoader.loadImage(currentAttraction.attractionImageSmall, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        Bitmap image = ImageHelper.scaleCenterCrop(loadedImage, 156, 156);
        image = ImageHelper.getRoundCornerBitmap(image, 14);
        attractionRowViewHolder.imageView.setImageBitmap(image);
    }
    });