sparragol
sparragol

Reputation: 75

NullPointerException when trying to load local images with ImageLoader

I'm trying to use the nostra13/ImageLoader (https://github.com/nostra13/Android-Universal-Image-Loader) in an activity which allows the user to pick an image from the Media Gallery or take a new one with the camera. When this action is complete, I have a full path to the picture in the form "/mnt/sdcard/DCIM/100ANDRO/whatever.jpg", that's to say an image saved in the sdcard. When I try to load this image with the ImageLoader I get the following error:

11-12 16:05:18.966: E/ImageLoader(12905): null
11-12 16:05:18.966: E/ImageLoader(12905): java.lang.NullPointerException
11-12 16:05:18.966: E/ImageLoader(12905): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.saveImageOnDisc(LoadAndDisplayImageTask.java:239)
11-12 16:05:18.966: E/ImageLoader(12905): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:138)
11-12 16:05:18.966: E/ImageLoader(12905): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:72)
11-12 16:05:18.966: E/ImageLoader(12905): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
11-12 16:05:18.966: E/ImageLoader(12905): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
11-12 16:05:18.966: E/ImageLoader(12905): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
11-12 16:05:18.966: E/ImageLoader(12905): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
11-12 16:05:18.966: E/ImageLoader(12905): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
11-12 16:05:18.966: E/ImageLoader(12905): at java.lang.Thread.run(Thread.java:1019)

I'm not really understanding the error, the path to the image is not null neither the Image View where I'm trying to load the image. I have the necessary permissions ons the manifest, and I'm able to load remote images but not the local ones. Any idea about what can be happening?

Thank you in advance!

This is my configuration:

 imageLoader = ImageLoader.getInstance();
 DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
 .cacheInMemory()
 .cacheOnDisc()
 .showImageForEmptyUri(R.drawable.image_broken)
 .build();
 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
 .memoryCache(new WeakMemoryCache())
 .threadPoolSize(4)
 .defaultDisplayImageOptions(defaultOptions)
 .build();
 imageLoader.init(config);

This is how I try to load the image into the imageview:

ImageView m_ivAvatar = (ImageView) findViewById(R.id.pdi_image_detail);
imageLoader.displayImage(imagen.getUrl(), m_ivAvatar);

And the xml:

<RelativeLayout 
        android:id="@+id/pdi_header_detail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView 
        android:id="@+id/pdi_image_detail"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:scaleType="fitCenter"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"/>

    <RelativeLayout 
        android:id="@+id/pdi_detail_action_icons_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true">

        <ImageButton 
            android:id="@+id/pdi_detail_icon_share"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:scaleType="fitCenter"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"/>

        <ImageButton 
            android:id="@+id/pdi_detail_icon_map"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:scaleType="fitCenter"
            android:layout_below="@id/pdi_detalle_icon_share"
            android:layout_alignParentLeft="true"/>

    </RelativeLayout>

</RelativeLayout>

Upvotes: 3

Views: 1852

Answers (1)

nostra13
nostra13

Reputation: 12407

Local file path for ImageLoader should start with file://. E.g. file:///mnt/sdcard/...

Upvotes: 2

Related Questions