쓰레드를 사용하여 이미지를 연속적으로 받아오는 프로그램을 만들어보았는데 에러가 납니다 도와주세요

 

쓰레드에 핸들러를 사용하면 에러는 안나는데 이유는 잘 모르겟네요,,

 

쓰레드만 사용하면 왜 에러가 나는지,,ㅠㅠ

 public class SingleView extends Activity {
 static ImageView imgView;
 static String imagePath;
 LoadImageThread LoadImageMain;
 static boolean loop = false;
 static boolean mQuit = false;


 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.single);
  imgView = (ImageView) findViewById(R.id.imgview);
  imagePath = "http://myhome/cam_1.jpg";
  LoadImageThread LoadImageMain = new LoadImageThread();
  LoadImageMain.start();
 }


 public void LoadImage(String $imagePath, ImageView ImageView) {
  // TODO Auto-generated method stub
  InputStream inputStream = OpenHttpConnection($imagePath);
  Bitmap bm = BitmapFactory.decodeStream(inputStream);
  ImageView.setImageBitmap(bm);
 }


 // /원본
 class LoadImageThread extends Thread {
  public void run() {
   while (true) {
    LoadImage(imagePath, imgView);
    try {
     Thread.sleep(600);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }
  }
 }


 private InputStream OpenHttpConnection(String $imagePath) {
  // TODO Auto-generated method stub
  InputStream stream = null;
  HttpURLConnection urlConnection = null;
  try {
   URL url = new URL("$imagePath);
   urlConnection = (HttpURLConnection) url.openConnection();
   urlConnection.setRequestMethod("GET");
   urlConnection.connect();
   if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
    stream = urlConnection.getInputStream();
   }
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return stream;
 }

 

이렇게 작성하면 에러가 발생하게 됩니다,ㅠㅠ

 

 class LoadImageThread extends Thread {
  
  public void run() {
   while (true) {
    handler.sendEmptyMessage(0);
    try {
     Thread.sleep(600);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }
  }
 }

 Handler handler = new Handler() {
  @Override
  public void handleMessage(Message msg) {
   LoadImage(imagePath, imgView);
   super.handleMessage(msg);
  }
 };

이렇게 작성하면 또 에러는 안나고 잘 작동하네요

 

어디에 에러가 있는지, 어느 부분을 고쳐야 하나요~?

도움바랍니다^^*