1

Hi i m using Android Studio, and I am using Deprecated function in a runOnUiThread It forces me to use a a Final Variable inside the runOnUiThread this is ok for the new function but for the Deprecated function i get an error

Error:(133, 16) error: incompatible types
required: Thread
found:    void

anyone can help to fix this.

    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();
asmgx
  • 7,328
  • 15
  • 82
  • 143

2 Answers2

3

your problem is not the setBackgroudDrawable method, but Thread.start(), which returns nothing (void), while you are trying to assign its return value to the thread local variable

You can both change Thread thread = new Thread() { ... } and then call thread.start() or simply new Thread() { ... }.start(); without assignment

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • 1
    thanks that was a quick answer, thanks a lot I used thread.start(); instead seems ok. – asmgx Jul 15 '14 at 09:21
1

Do you need to use the thread variable anywhere else? I don't think you need to. If so, simply change in your first line

 Thread thread = new Thread() {

To

new Thread() {

Your .start() will return void, and you cannot do Thread thread=//some thing void as it is expecting some Thread type.

Kartik_Koro
  • 1,277
  • 1
  • 11
  • 23