嗨,我正在使用 Android Studio,我在 runOnUiThread 中使用不推荐使用的函数它迫使我在 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();