简体   繁体   English

尝试使用ImageLoader加载本地图像时出现NullPointerException

[英]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. 我正在尝试在一个活动中使用nostra13 / ImageLoader( https://github.com/nostra13/Android-Universal-Image-Loader ),该活动允许用户从媒体库中选择一个图像或者使用一个新的图像。相机。 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. 完成此操作后,我将以“/mnt/sdcard/DCIM/100ANDRO/whatever.jpg”形式显示图片的完整路径,也就是说保存在SD卡中的图像。 When I try to load this image with the ImageLoader I get the following error: 当我尝试使用ImageLoader加载此图像时,出现以下错误:

11-12 16:05:18.966: E/ImageLoader(12905): null 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):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.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.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 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.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 $ 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.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.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.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) 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中的方法:

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

And the xml: 和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>

Local file path for ImageLoader should start with file:// . ImageLoader的本地文件路径应以file://开头。 Eg file:///mnt/sdcard/... 例如file:/// mnt / sdcard / ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM