【发布时间】:2019-06-11 09:04:54
【问题描述】:
我正在尝试从 url 异步加载图像(在后台线程上)。
尝试这样的事情:
val futureTarget = glide
.asBitmap()
.load("https://dummyimage.com/300/09f/fff.png")
.submit(300, 300)
val bitmap = futureTarget.get()
但是在尝试从 URL 加载任何图像时它会导致应用程序崩溃,在加载本地资源时它工作正常。
Logcat
There was 1 cause:
com.bumptech.glide.load.HttpException(Not Found)
call GlideException#logRootCauses(String) for more detail
at com.bumptech.glide.request.RequestFutureTarget.doGet(RequestFutureTarget.java:205)
at com.bumptech.glide.request.RequestFutureTarget.get(RequestFutureTarget.java:108)
at com.....Notifier$sendNotificationTest$1.run(Notifier.kt:85)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
com.bumptech.glide.load.HttpException(Not Found)
call GlideException#logRootCauses(String) for more detail
我已添加 Internet 权限。
<uses-permission android:name="android.permission.INTERNET" />
使用 Dagger 2 提供 Glide
@Provides
@Singleton
static RequestManager provideGlide(final Application application) {
return GlideApp.with(application);
}
知道我错过了什么吗?
更新
我发现某些 HttpInterceptor 存在问题。此解决方案可同步下载位图。
【问题讨论】:
-
您是否在清单中启用了互联网权限?
-
请检查您是否在AndroidManifest.xml中添加了INTERNET_PERMISSION。
-
是的,我在尝试加载图像时在应用程序内。
-
你在创建 glide 的实例吗?
-
是的,刚刚编辑了问题:)
标签: android kotlin android-glide android-image