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

cngwdvgl  于 2022-12-09  发布在  Android
关注(0)|答案(3)|浏览(441)

我使用滑动加载图像到Drawable对象。当我尝试加载本Map像时,它工作正常。但是,我从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

下面是我的错误堆栈跟踪:

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) 

上面是我的错误跟踪,我在回调中调试它。下面是我的实现:

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()
        }
    })
ikfrs5lh

ikfrs5lh1#

在我的例子中,触发这个错误是因为我试图在主Activity线程之外的Glide回调内更新UI。
它在堆栈跟踪的顶部并不明显,我必须仔细检查一下logcat才能意识到这就是问题所在。
在用.runOnUiThread(..) Package 所有UI更新调用(* 在Glide回调方法中 *)后,异常消失了。

ugmeyewa

ugmeyewa2#

我知道这是一个晚重播,可能会对其他任何人有帮助。
由于您的链接是从HTTPS我认为你需要有一个SSL验证器接受数据从https链接。请检查心爱的链接
accepting HTTPS connections with self-signed certificates

uxhixvfz

uxhixvfz3#

检查您是否在AndroidManifest.xml中添加了Internet权限

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

更新:
来自收存箱的实际图像URL为:
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
我能够使用此URL成功加载。
所以我猜Dropbox是重定向到网页,如果你是使用以前的网址。

相关问题