Picasso java.lang.IllegalStateException:方法调用不应从主线程发生 [英] Picasso java.lang.IllegalStateException: Method call should not happen from the main thread

查看:35
本文介绍了Picasso java.lang.IllegalStateException:方法调用不应从主线程发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Picasso 从 URL

I am attempting to use Picasso to get three Bitmap images from a URL

public void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState);
  setContentView(R.layout.tab2);
  Drawable d1 = new BitmapDrawable(Picasso.with(Tab2.this).load(zestimateImg1).get());
}

我收到此代码的FATAL EXCEPTION.我怀疑这与这应该在 AsyncTask 中完成的事实有关,但我无法让它工作.如果使用它是可以避免的,我想在不使用 AsyncTask 的情况下做到这一点.

I am getting FATAL EXCEPTION with this code. I suspect it has to do with the fact that this should be done within AsyncTask, but I can't get it to work. If using that is avoidable, I would like to do this without using AsyncTask.

我怎样才能让这段代码在不崩溃的情况下运行?

How can I get this code to run without crashing?

如果最好的方法是使用 AsyncTask,那么这个解决方案就可以了.

If the best way to do this is with AsyncTask, then that solution is ok.

推荐答案

以上都不适合我

Handler uiHandler = new Handler(Looper.getMainLooper());
    uiHandler.post(new Runnable(){
        @Override
        public void run() {
            Picasso.with(Context)
                    .load(imageUrl)
                    .into(imageView);
        }
    });

希望对大家有用

这篇关于Picasso java.lang.IllegalStateException:方法调用不应从主线程发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆