Glide 有时不工作但有时它工作
Glide sometime not working but sometime it works
我正在使用 Glide v4,它并不总是可以从 Url 获取位图。有时有效,有时无效并抛出异常。我不知道为什么。这是异常:java.lang.IllegalArgumentException: You must call this method on a background thread
这是我的代码:
try {
bitmap=Glide.with(mContext.getApplicationContext())
.asBitmap().load(icon).fitCenter()
.circleCrop().submit().get();
} catch (Exception e) {
bitmap= BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.ic_default_user_image);
}
我在使用 Glide 时遇到了另一个问题,这是我在 Glide Github 上提出的问题:https://github.com/bumptech/glide/issues/3590
异常表示 - "You must call this method on a background thread",例如:
Thread mThread = new Thread(new Runnable() {
@Override
public void run() {
try {
//Put your code that you want to run in here
} catch (Exception e) {
e.printStackTrace();
}
}
});
mThread.start
java.lang.IllegalArgumentException: 您必须在后台线程上调用此方法
异常很明显。您不能 运行 在主线程(即 UI 线程)上加载 img 的代码。这 可能会解决您的问题。
我正在使用 Glide v4,它并不总是可以从 Url 获取位图。有时有效,有时无效并抛出异常。我不知道为什么。这是异常:java.lang.IllegalArgumentException: You must call this method on a background thread
这是我的代码:
try {
bitmap=Glide.with(mContext.getApplicationContext())
.asBitmap().load(icon).fitCenter()
.circleCrop().submit().get();
} catch (Exception e) {
bitmap= BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.ic_default_user_image);
}
我在使用 Glide 时遇到了另一个问题,这是我在 Glide Github 上提出的问题:https://github.com/bumptech/glide/issues/3590
异常表示 - "You must call this method on a background thread",例如:
Thread mThread = new Thread(new Runnable() {
@Override
public void run() {
try {
//Put your code that you want to run in here
} catch (Exception e) {
e.printStackTrace();
}
}
});
mThread.start
java.lang.IllegalArgumentException: 您必须在后台线程上调用此方法
异常很明显。您不能 运行 在主线程(即 UI 线程)上加载 img 的代码。这