簡體   English   中英

嘗試使用ImageLoader加載本地圖像時出現NullPointerException

[英]NullPointerException when trying to load local images with ImageLoader

我正在嘗試在一個活動中使用nostra13 / ImageLoader( https://github.com/nostra13/Android-Universal-Image-Loader ),該活動允許用戶從媒體庫中選擇一個圖像或者使用一個新的圖像。相機。 完成此操作后,我將以“/mnt/sdcard/DCIM/100ANDRO/whatever.jpg”形式顯示圖片的完整路徑,也就是說保存在SD卡中的圖像。 當我嘗試使用ImageLoader加載此圖像時,出現以下錯誤:

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>

ImageLoader的本地文件路徑應以file://開頭。 例如file:/// mnt / sdcard / ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM