【问题标题】:Unable to understand this stack trace(parse.com)无法理解此堆栈跟踪(parse.com)
【发布时间】:2015-12-31 07:40:08
【问题描述】:

我在我的应用程序中使用 crashylytics。它已经投入生产大约 2 个月。我遇到了一些我能够解决的崩溃,但是最近几天我得到了一个堆栈跟踪,它没有将我指向我的代码(甚至是一个活动)中发生崩溃的行。

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 卡上的位置和一个浮点数,该浮点数确定图像重新缩放后最大尺寸的尺寸。

【问题讨论】:

  • 我倾向于相信这个问题或多或少与您面临的问题相同; stackoverflow.com/questions/26411710/….
  • 我还认为崩溃可能是由于使用 Parse 上传了多个位图。如果我需要上传 6-7 个位图,每个大小为 200kb,将它们保存为解析文件并从它们中创建指向原始对象的指针,那么有效的方法是什么?在 onClick 本身中编写代码会导致 UI 冻结

标签: android apache parse-platform crash crashlytics


【解决方案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);

希望对您有所帮助!

【讨论】:

  • 我已经看到了这段代码,并用它做了一些改动。我已经添加了新代码。请帮帮我。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-10
  • 1970-01-01
  • 1970-01-01
  • 2014-10-07
  • 2010-09-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多