Android: thread stop working
<p>It reads image from the channel and write it to card. the image in card is completely written and is fine. The only problem is thread in hanged and does not execute any line after that loop. </p>

<pre><code>protected Bitmap doInBackground(String... arg0) {
    // TODO Auto-generated method stub'
      // Runtime.getRuntime().availableProcessors();
    System.out.println("Inside doinback"+ RemoteScreen.out.toString());
        try {
            RemoteScreen.out.write(210);
            //Home.threadloop = false;  
             Bitmap bitmap = null;  
            String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
            String fileName = "a.png";
            String imageInSD = baseDir + File.separator + fileName; 
                System.out.println(imageInSD);
            if (is!= null) {
                FileOutputStream fos = null;
                BufferedOutputStream bos = null;
                try {
                    // Log.i("IMSERVICE", "FILERECCC-1");
                    //ContextWrapper context = null;
                    fos = new FileOutputStream(imageInSD);   
                    bos = new BufferedOutputStream(fos);

                    byte[] aByte = new byte[1024]; 
                    int bytesRead;  
                    //thread stuck in this loop and does not move forward 
                    while ( (bytesRead = is.read(aByte)) &gt; 0  ) {
                        if (bytesRead == 1)
                            break; 
                        bos.write(aByte, 0, bytesRead);  
                   System.out.println("Loop"+aByte); 

                    }   

                   bos.close();

                Log.i("IMSERVICE", "out of loop");     
                    java.io.FileInputStream in = new FileInputStream(imageInSD);
               bitmap = BitmapFactory.decodeStream(in);
                  bitmap = BitmapFactory.decodeFile(imageInSD); 

            Log.i("IMSERVICE", "saved");
                if (bitmap != null) 
                    System.out.println(bitmap.toString());

                } catch (IOException ex) {    
                    // Do exception handling      
             //     Log.i("IMSERVICE", "exception ");
                }
            }
             publishProgress(b);   
             b = null; 
             ch = 4646;

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



     return null;
}
</code></pre>

<p>log trace shows following error.</p>

<pre><code>   05-10 20:34:42.715: E/AndroidRuntime(1135): FATAL EXCEPTION: AsyncTask #3
  05-10 20:34:42.715: E/AndroidRuntime(1135): java.lang.RuntimeException: An error occured while executing doInBackground()
  05-10 20:34:42.715: E/AndroidRuntime(1135):   at android.os.AsyncTask$3.done(AsyncTask.java:299)
    05-10 20:34:42.715: E/AndroidRuntime(1135):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
   05-10 20:34:42.715: E/AndroidRuntime(1135):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
    05-10 20:34:42.715: E/AndroidRuntime(1135):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
    05-10 20:34:42.715: E/AndroidRuntime(1135):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  05-10 20:34:42.715: E/AndroidRuntime(1135):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
 05-10 20:34:42.715: E/AndroidRuntime(1135):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
 05-10 20:34:42.715: E/AndroidRuntime(1135):    at java.lang.Thread.run(Thread.java:856)
 05-10 20:34:42.715: E/AndroidRuntime(1135): Caused by: java.lang.NullPointerException
 05-10 20:34:42.715: E/AndroidRuntime(1135):    at com.rms.remotedesktop1.screencahnge.doInBackground(screencahnge.java:43)
 05-10 20:34:42.715: E/AndroidRuntime(1135):    at com.rms.remotedesktop1.screencahnge.doInBackground(screencahnge.java:1)
 05-10 20:34:42.715: E/AndroidRuntime(1135):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
 05-10 20:34:42.715: E/AndroidRuntime(1135):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
</code></pre>
