滑行有时不工作,但有时它工作

问题描述 投票:2回答:2

我正在使用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

android android-glide
2个回答
1
投票

例外情况说 - “你必须在后台线程上调用此方法”,例如:

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

2
投票

java.lang.IllegalArgumentException:您必须在后台线程上调用此方法

例外很清楚。你无法运行在主线程(即UI线程)上加载img的代码。这个link可以解决你的问题。

© www.soinside.com 2019 - 2024. All rights reserved.