首页 > 解决方案 > Glide - 加载失败的图像大小

问题描述

我有以下代码行,Android AppGlide拒绝向我显示图像:

requestManager.load(profilePicturePath).into(binding.profilePic)

调试显示profilePicturePath有值/media/Images/place.jpg。该文件存在于我的本地Django开发服务器上。我可以通过PostMan.

但是在AndroidGlide中,我收到以下错误消息:

2020-11-22 15:24:08.846 7284-7284/com.example.project W/Glide: Load failed for /media/Images/place.jpg with size [1080x1437]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 3 causes:
    java.io.FileNotFoundException(/media/Images/place.jpg (No such file or directory))
    java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
    java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(/media/Images/place.jpg (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
    There was 1 cause:
    java.io.FileNotFoundException(/media/Images/place.jpg (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.FileNotFoundException: /media/Images/place.jpg (No such file or directory)
      Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.os.ParcelFileDescriptor, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
    There was 1 cause:
    java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
      Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.content.res.AssetFileDescriptor, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)

我的问题:

1.) Why is this error happening ? 
2.) The image `place.jpg` has the dimension width=316 and height=159 . But Glide states that the image size is [1080x1437]. Why?

标签: androiddjango-rest-frameworkandroid-glidefilenotfoundexception

解决方案


这是由于范围存储。在 andriod Q 或更高版本中,您无法直接从图像路径访问。您可以使用:

android:requestLegacyExternalStorage="true" android:preserveLegacyExternalStorage="true"

这两个在清单中的应用程序标记中,因此它适用于 android Q,但不适用于下一个版本。您需要实现 Mediastore API


推荐阅读