简体   繁体   English

尝试从 URL 加载图像时,Glide 无法加载资源

[英]Glide fails to load resources when trying to load an image from a URL

i use glide to load image into Drawable object.我使用 glide 将图像加载到 Drawable 对象中。 When i try to load local image, it works fine.当我尝试加载本地图像时,它工作正常。 But, i switch to image from url, it won't work and i get this error message :但是,我从 url 切换到图像,它不起作用,我收到此错误消息:

W/Glide: Load failed for https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png with size [-2147483648x-2147483648]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
      Cause (1 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{DirectByteBuffer->Object->Drawable}, DATA_DISK_CACHE, https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->Bitmap->Drawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->BitmapDrawable->Drawable}
      Cause (2 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{FileInputStream->Object->Drawable}, DATA_DISK_CACHE, https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->Bitmap->Drawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->BitmapDrawable->Drawable}
      Cause (3 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{ParcelFileDescriptor->Object->Drawable}, DATA_DISK_CACHE, https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png
        Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->Bitmap->Drawable}
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0x80000000
        Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->BitmapDrawable->Drawable}
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0x80000000
      Cause (4 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{DirectByteBuffer->Object->Drawable}, REMOTE, https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->Bitmap->Drawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->BitmapDrawable->Drawable}
      Cause (5 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{FileInputStream->Object->Drawable}, REMOTE, https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->Bitmap->Drawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->BitmapDrawable->Drawable}
      Cause (6 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{ParcelFileDescriptor->Object->Drawable}, REMOTE, https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png
        Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->Bitmap->Drawable}
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0x80000000
        Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->BitmapDrawable->Drawable}
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0x80000000

And here is my error stack trace :这是我的错误堆栈跟踪:

 Caused by: java.lang.RuntimeException: setDataSource failed: status = 0x80000000
    at android.media.MediaMetadataRetriever.setDataSource(Native Method)
    at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:144)
    at com.bumptech.glide.load.resource.bitmap.VideoBitmapDecoder.decode(VideoBitmapDecoder.java:128)
    at com.bumptech.glide.load.resource.bitmap.VideoBitmapDecoder.decode(VideoBitmapDecoder.java:25) 
    ..... .... ...
    at com.bumptech.glide.load.model.ByteBufferFileLoader$ByteBufferFetcher.loadData(ByteBufferFileLoader.java:72) 
    at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:71) 
    at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:303) 
    at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:270) 
    at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
    at java.lang.Thread.run(Thread.java:818) 
    at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:445) 

Above is my error trace, i debug it in callback.以上是我的错误跟踪,我在回调中调试它。 Here is my implementation :这是我的实现:

Glide.with(context)
    .load("https://www.dropbox.com/s/nx8ufy3jxc9urgv/ic_reward_3rb.png")
    .into(object : SimpleTarget<Drawable>() {
        override fun onResourceReady(downloadedResource: Drawable, transition: Transition<in Drawable>) {
            Log.e("GameRejeki", "Resource is Ready...")
            downloadedResource.setBounds(
                    leftSize + leftSize / 2 - rewardIconWidth / 3,
                    topSize,
                    widthSize + leftSize / 2 - rewardIconWidth / 3,
                    heightSize
            )

            canvas.save()
            canvas.rotate(value, leftSize.toFloat(), leftSize.toFloat())
            downloadedResource.draw(canvas)
            canvas.restore()
        }
    })

In my case, this error was getting triggered because I was trying to update the UI inside the Glide callback, outside the main Activity thread.在我的例子中,这个错误被触发是因为我试图在主 Activity 线程之外更新 Glide 回调内的 UI。

It was not apparent at the top of the stack trace, and I had to scrutinize logcat a bit to realize this was the problem.它在堆栈跟踪的顶部并不明显,我不得不仔细检查 logcat 以意识到这是问题所在。

After wrapping all UI update calls - that were inside the Glide callback methods - with .runOnUiThread(..) , the exception went away.在使用.runOnUiThread(..)包装所有 UI 更新调用(在 Glide 回调方法中.runOnUiThread(..) ,异常消失了。

I know its a late replay, may be helpful for anyone else.我知道这是一个较晚的重播,可能对其他人有帮助。

Since your link is from HTTPS I think you need to have an SSL verifier to accept data from https link.由于您的链接来自 HTTPS,我认为您需要一个 SSL 验证程序来接受来自 https 链接的数据。 kindly check the belove link请检查亲爱的链接

accepting HTTPS connections with self-signed certificates 接受带有自签名证书的 HTTPS 连接

Check if you added internet permission in AndroidManifest.xml检查您是否在AndroidManifest.xml添加了互联网权限

<uses-permission android:name="android.permission.INTERNET" />

Update :更新:

Actual image url from dropbox is :来自 Dropbox 的实际图片网址是:

https://photos-1.dropbox.com/t/2/AACkTffiGl7ApXhQS7i_wAs-VlEdi2hukrOrjBaj5fZe2A/12/117339454/png/32x32/3/1524150000/0/2/ic_reward_3rb.png/EN2_w1oYmYoDIAIoAg/4m_AZbPL_PKPAjLx4EdcJeRWU8hrrlf-SXDFk-mhlYQ?dl=0&preserve_transparency=1&size=2048x1536&size_mode=3

I was able to load successfully using this url.我能够使用这个 url 成功加载。

So I guess dropbox is redirecting to webpage if you are using the previous url.所以我猜如果您使用以前的网址,dropbox 会重定向到网页。

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

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