imgView.setBitmap can not be called from any other thread than the
main thread (i.e. thread on which you created your view).

do this instead:

handler.post(new Runnable() {
  public void run() {
    imgView.setBitmap(bm);
  }
});

The 'handler' can be created by just calling 'new Handler()' on the
main thread, e.g. when you create your worker-thread.

public MyThread extends Thread {
  Handler handler;
  public MyThread() {
    super();
     handler = new Handler();
  }
  public void run() {
    ..
    ...
    handler.post(new Runnable() {
      public void run() {
        imgView.setBitmap(bm);
      }
    });
    ...
  }
}
On Mar 2, 4:47 am, rex <[email protected]> wrote:
> Hi~
>
> I'm trying to periodically change image data in ImageView in the
> thread routine
> but when I put this code in the tread routine, program is killed.
>
>  imgView.setBitmap(bm);
>
> here is my thread code
> ...
>
> private byte[] imgData;
> private Bitmap bm;
>
> new Thread (new Runnable()
> {
>     public void run()
>     {
>         while(!isStop){
>                    imgData = getImage();
>                    bm = BitmapFactory.decodeByteArray(imgData,
> 0,imgData.length);
>                    imgView.setBitmap(bm); --> This caused error!!
>         }
>      }
>
> }).start();
>
> ...
>
> imgData is receiving jpeg image data from somewhere.
> Outside thread routine, image data is displayed well.
>
> If above is impossible, are there any other ways to periodically image
> data refreshing on screen ?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to