Java android:runOnUiThread中的变量

Java android:runOnUiThread中的变量,java,android,multithreading,final,webviewrunonuithread,Java,Android,Multithreading,Final,Webviewrunonuithread,您好,我使用的是Android Studio,我在RunNuithread中使用的是不推荐使用的函数 它迫使我在runOnUiThread中使用最后一个变量 对于新函数,这是可以的,但是对于不推荐使用的函数,我得到了一个错误 Error:(133, 16) error: incompatible types required: Thread found: void 任何人都可以帮助解决这个问题 Thread thread = new Thread() { publ

您好,我使用的是Android Studio,我在RunNuithread中使用的是不推荐使用的函数 它迫使我在runOnUiThread中使用最后一个变量 对于新函数,这是可以的,但是对于不推荐使用的函数,我得到了一个错误

Error:(133, 16) error: incompatible types
required: Thread
found:    void
任何人都可以帮助解决这个问题

    Thread thread = new Thread() {
        public void run() {
            try {
                String sURL = "http://pollsdb.com/schlogger/223.png";

                URL url = null;
                url = new URL(sURL);
                assert url != null;

                Bitmap bmp = null;
                bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                bmp = Bitmap.createScaledBitmap(bmp, 200, 200, false);
                BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bmp);

                final BitmapDrawable fbmpdw = bitmapDrawable;

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ib1.setBackground(fbmpdw);
                        } else {
                            ib1.setBackgroundDrawable(fbmpdw); // <---- this the problem
                        }
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
Thread-Thread=新线程(){
公开募捐{
试一试{
字符串sURL=”http://pollsdb.com/schlogger/223.png";
URL=null;
url=新url(sURL);
断言url!=null;
位图bmp=null;
bmp=BitmapFactory.decodeStream(url.openConnection().getInputStream());
bmp=Bitmap.createScaledBitmap(bmp,200,200,false);
BitmapDrawable BitmapDrawable=新的BitmapDrawable(getResources(),bmp);
最终可位图绘制fbmpdw=可位图绘制;
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.JELLY\u BEAN){
ib1.立根背景(fbmpdw);
}否则{

ib1.setBackgroundDrawable(fbmpdw);//您的问题不是
setBackgroundDrawable
方法,而是
Thread.start()
,当您试图将其返回值分配给
Thread
局部变量时,它不返回任何内容(
void


您既可以更改
Thread-Thread=new-Thread(){…}
,然后调用
Thread.start()
,也可以只调用
new-Thread(){…}.start();
而不进行赋值

您的问题不是
setbackgroupddravable
方法,而是
Thread.start()
,它不返回任何内容(
void
),而您正试图将其返回值分配给
线程
局部变量


您既可以更改
Thread-Thread=new-Thread(){…}
,然后调用
Thread.start()
,也可以只调用
new-Thread(){…}.start();
而无需赋值

是否需要在其他任何地方使用
Thread
变量?我认为不需要。 如果是这样,只需在第一行中更改即可

 Thread thread = new Thread() {


您的.start()将返回void,并且您不能执行
Thread-Thread=///something-void
,因为它需要某种线程类型。

是否需要在其他任何地方使用
Thread
变量?我认为您不需要这样做。 如果是这样,只需在第一行中更改即可

 Thread thread = new Thread() {


你的.start()将返回void,你不能执行
Thread-Thread=///some thing-void
,因为它需要一些线程类型。

谢谢这是一个快速的答案,非常感谢我使用了Thread.start();相反,似乎还可以。谢谢这是一个快速的答案,非常感谢我使用了Thread.start();看起来还可以。