2015-12-31 119 views
0

我在應用程序中使用了crashylytics。它已經生產了大約2個月。我已經解決了一些崩潰問題,但是最近幾天我得到了一個堆棧跟蹤,這個堆棧跟蹤並沒有指向我的代碼(甚至是一個活動),在這一點上崩潰發生。無法理解此堆棧跟蹤(parse.com)

Fatal Exception: java.lang.OutOfMemoryError 
     at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:120) 
     at org.apache.http.conn.BasicManagedEntity.eofDetected(BasicManagedEntity.java:161) 
     at org.apache.http.conn.EofSensorInputStream.checkEOF(EofSensorInputStream.java:239) 
     at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:179) 
     at com.parse.ParseIOUtils.copyLarge(ParseIOUtils.java:129) 
     at com.parse.ParseIOUtils.copyLarge(ParseIOUtils.java:106) 
     at com.parse.ParseIOUtils.copy(ParseIOUtils.java:81) 
     at com.parse.ParseIOUtils.toByteArray(ParseIOUtils.java:55) 
     at com.parse.ParseRESTObjectBatchCommand.onResponse(ParseRESTObjectBatchCommand.java:66) 
     at com.parse.ParseRequest$3.then(ParseRequest.java:229) 
     at com.parse.ParseRequest$3.then(ParseRequest.java:225) 
     at bolts.Task$10.run(Task.java:486) 
     at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97) 
     at bolts.Task.completeAfterTask(Task.java:482) 
     at bolts.Task.continueWithTask(Task.java:358) 
     at bolts.Task.continueWithTask(Task.java:369) 
     at bolts.Task$8.then(Task.java:415) 
     at bolts.Task$8.then(Task.java:407) 
     at bolts.Task$10.run(Task.java:486) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:841) 

而這。

Fatal Exception: java.lang.OutOfMemoryError 
     at org.apache.http.util.ByteArrayBuffer.<init>(ByteArrayBuffer.java:53) 
     at org.apache.http.impl.io.AbstractSessionInputBuffer.init(AbstractSessionInputBuffer.java:82) 
     at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:70) 
     at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83) 
     at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170) 
     at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106) 
     at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129) 
     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:172) 
     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 
     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 
     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365) 
     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:587) 
     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:511) 
     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:489) 
     at com.parse.ParseApacheHttpClient.execute(ParseApacheHttpClient.java:97) 
     at com.parse.ParseRequest$3.then(ParseRequest.java:228) 
     at com.parse.ParseRequest$3.then(ParseRequest.java:225) 
     at bolts.Task$10.run(Task.java:486) 
     at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97) 
     at bolts.Task.completeAfterTask(Task.java:482) 
     at bolts.Task.continueWithTask(Task.java:358) 
     at bolts.Task.continueWithTask(Task.java:369) 
     at bolts.Task$8.then(Task.java:415) 
     at bolts.Task$8.then(Task.java:407) 
     at bolts.Task$10.run(Task.java:486) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:841) 

通常死機我發現一行

at com.justmedit.datatrix.MainActivity$1.done(MainActivity.java:90)

指向我導致崩潰的行。 有人可能請給我建議,爲什麼會發生這種情況或可能性,以便我可以調查此問題並在下一個版本中修復它。謝謝!

我使用縮放位圖

添加的代碼 -

public Bitmap ScaleImage(String value, float dimension){ 
     Bitmap bitmap = BitmapFactory.decodeFile(value); 
     int width = bitmap.getWidth(); 
     int height = bitmap.getHeight(); 
     float scale; 
     if (width>height){scale=dimension/width;} 
     else {scale=dimension/height;} 
     ExifInterface exif; 
     Matrix matrix = new Matrix(); 
     try { 
      exif = new ExifInterface(value); 
      int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); 
      Log.d("EXIF", "Exif: " + orientation); 
      if (orientation == 6) { 
       matrix.postRotate(90); 
       Log.d("EXIF", "Exif: " + orientation); 
      } else if (orientation == 3) { 
       matrix.postRotate(180); 
       Log.d("EXIF", "Exif: " + orientation); 
      } else if (orientation == 8) { 
       matrix.postRotate(270); 
       Log.d("EXIF", "Exif: " + orientation);} 

     }catch (IOException e){e.printStackTrace();} 
     matrix.postScale(scale, scale); 
     Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,width, height, matrix, true); 
     return resizedBitmap; 
    } 

這讓我通過SD卡和一個浮點數這就決定了最大尺寸的大小對圖像的位置,一旦圖像被重新調整。

+0

我傾向於認爲這個問題或多或少是你面臨的問題; http://stackoverflow.com/questions/26411710/fatal-exception-outofmemoryerror。 – harism

+0

我也相信崩潰可能是由於使用Parse上傳多個位圖。如果我需要上傳6-7位圖,每個位圖大小爲200kb,將它們保存爲解析文件並將它們指向原始對象,那麼這將是一種有效的方法嗎?在onClick中編寫代碼本身導致用戶界面凍結 –

回答

1

您必須在樣本大小中創建位圖。看看Loading bitmaps efficiently

public static int calculateInSampleSize(

     BitmapFactory.Options options, int reqWidth, int reqHeight) { 
     // Raw height and width of image 
     final int height = options.outHeight; 
     final int width = options.outWidth; 
     int inSampleSize = 1; 

     if (height > reqHeight || width > reqWidth) { 
     if (width > height) { 
     inSampleSize = Math.round((float) height 
     /(float) reqHeight); 
     } else { 
     inSampleSize = Math.round((float) width/(float) reqWidth); 
     } 
     } 

     return inSampleSize; 
     } 

下面的方法將在樣本大小從Byte陣列解碼Bitmap

public static Bitmap decodeSampledBitmapFromBytes(byte[] bytes, int reqWidth, 
     int reqHeight) { 

     Bitmap bm = null; 
     // First decode with inJustDecodeBounds=true to check dimensions 
     final BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); 

     // Calculate inSampleSize 
     options.inSampleSize = calculateInSampleSize(options, reqWidth, 
     reqHeight); 

     // Decode bitmap with inSampleSize set 
     options.inJustDecodeBounds = false; 
     bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); 

     return bm; 
     } 

     public static int calculateInSampleSize(

     BitmapFactory.Options options, int reqWidth, int reqHeight) { 
     // Raw height and width of image 
     final int height = options.outHeight; 
     final int width = options.outWidth; 
     int inSampleSize = 1; 

     if (height > reqHeight || width > reqWidth) { 
     if (width > height) { 
     inSampleSize = Math.round((float) height 
     /(float) reqHeight); 
     } else { 
     inSampleSize = Math.round((float) width/(float) reqWidth); 
     } 
     } 

     return inSampleSize; 
     } 

100是高度和寬度,您可以根據自己的需要進行修改。

Bitmap bitmap = decodeSampledBitmapFromBytes(bytes, 100, 100); 

希望它能幫上忙。

+0

我已經看到了這段代碼,並用它進行了一些更改。我已經添加了新的代碼。請幫助我。謝謝 –