1

它从通道读取图像并将其写入卡。卡片中的图像已完全写入并且很好。唯一的问题是线程挂起并且在该循环之后不执行任何行。

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)) > 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;
}

日志跟踪显示以下错误。

   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)
4

2 回答 2

5

根据 logcat,代码在第 43 行崩溃,出现空指针异常,我不知道第 43 行是哪一行。然而:

于 2013-05-10T20:50:36.233 回答
0

我自己解决了这个问题。由于代码中的逻辑错误,正在更改其值的静态变量存在错误。

于 2013-05-11T09:46:12.893 回答