Reputation: 135
I am using Glide v4 and it is not always can get bitmap from Url. Sometimes it works and Sometimes it does not work and throw an exception. I don't know why. this is the Exception:java.lang.IllegalArgumentException: You must call this method on a background thread
and this is my code:
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);
}
I am facing another problem with Glide, this is the issue I made on Glide Github : https://github.com/bumptech/glide/issues/3590
Upvotes: 2
Views: 380
Reputation: 9425
java.lang.IllegalArgumentException: You must call this method on a background thread
The exception is very clear . you can't run your code that load a img on the main thread(which is UI Thread). This link may solve ur problem.
Upvotes: 2
Reputation: 7661
The exception says - "You must call this method on a background thread", for example :
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
Upvotes: 1