2012-11-13 135 views
3

我试图在允许用户从媒体库中选取图像或使用相机拍摄新图像的活动中使用nostra13/ImageLoader(https://github.com/nostra13/Android-Universal-Image-Loader)。完成此操作后,我会以“/mnt/sdcard/DCIM/100ANDRO/whatever.jpg”的形式显示完整路径,也就是说保存在SD卡中的图像。当我尝试用ImageLoader的我碰到下面的错误加载此图片:尝试使用ImageLoader加载本地图像时出现NullPointerException

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)

我真的不理解错误,图片路径不为空无论是图片浏览这里我想加载图像。我有必要的权限清单,我可以加载远程图像,但不是本地的。 关于可能发生什么的任何想法?

预先感谢您!

这是我的配置:

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); 

这是我尝试将图像加载到ImageView的:

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

和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> 
+0

imagen是什么? imagen.getURL()返回什么? – ariefbayu

+0

对不起。 imagen是表示应用程序内部图像的对象。它包含一些关于它的信息,包括getURL()方法返回的url(图像的完整路径)。这个URL可以是一个本地路径/mnt/sdcard/.../image.jpg或者远程http://.../image.jpg – sparragol

回答

2

本地文件路径对于ImageLoader应该从file://开始。 例如file:/// mnt/sdcard/...

+0

非常感谢你,知道它的作品!对我感到羞耻,我没有考虑将file://添加到本地路径。 – sparragol

+0

您应该阅读自述文件和Java文档。 – NOSTRA

相关问题