Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 越南元';t让我们分配**字节_Android_Memory_Logcat_Allocation_Android Logcat - Fatal编程技术网

Android 越南元';t让我们分配**字节

Android 越南元';t让我们分配**字节,android,memory,logcat,allocation,android-logcat,Android,Memory,Logcat,Allocation,Android Logcat,可能重复: 我的应用程序想要分配2529792字节,我在128mb Ram的设备上运行它,它工作正常,然后我在htc上运行ir,有292mb的Ram可用内存,它给出了错误 01-14 21:08:27.972:E/GraphicsJNI(26585):VM不允许我们分配2529792字节 这是我的LogCat输出 01-14 21:08:27.391: E/dalvikvm-heap(26585): 2529792-byte external allocation too large for

可能重复:

我的应用程序想要分配2529792字节,我在128mb Ram的设备上运行它,它工作正常,然后我在htc上运行ir,有292mb的Ram可用内存,它给出了错误

01-14 21:08:27.972:E/GraphicsJNI(26585):VM不允许我们分配2529792字节

这是我的LogCat输出

01-14 21:08:27.391: E/dalvikvm-heap(26585): 2529792-byte external allocation too large for this process.
01-14 21:08:27.411: E/dalvikvm(26585): Out of memory: Heap Size=17735KB, Allocated=14425KB, Bitmap Size=14641KB, Limit=32768KB
01-14 21:08:27.411: E/dalvikvm(26585): Trim info: Footprint=17735KB, Allowed Footprint=17735KB, Trimmed=668KB
01-14 21:08:27.512: E/GraphicsJNI(26585): VM won't let us allocate 2529792 bytes
01-14 21:08:27.512: D/dalvikvm(26585): GC_FOR_MALLOC freed 905K, 24% free 13520K/17735K, external 14641K/16689K, paused 93ms
01-14 21:08:27.652: D/dalvikvm(26585): GC_EXTERNAL_ALLOC freed 3K, 24% free 13552K/17735K, external 14641K/16689K, paused 116ms
01-14 21:08:27.662: D/skia(26585): --- decoder->decode returned false
01-14 21:08:27.792: D/dalvikvm(26585): GC_EXTERNAL_ALLOC freed 13K, 24% free 13655K/17735K, external 14641K/16689K, paused 109ms
01-14 21:08:27.872: E/dalvikvm-heap(26585): 2529792-byte external allocation too large for this process.
01-14 21:08:27.872: E/dalvikvm(26585): Out of memory: Heap Size=17735KB, Allocated=13655KB, Bitmap Size=14641KB, Limit=32768KB
01-14 21:08:27.872: E/dalvikvm(26585): Trim info: Footprint=17735KB, Allowed Footprint=17735KB, Trimmed=1408KB
01-14 21:08:27.972: E/GraphicsJNI(26585): VM won't let us allocate 2529792 bytes
01-14 21:08:27.972: D/dalvikvm(26585): GC_FOR_MALLOC freed 39K, 24% free 13615K/17735K, external 14641K/16689K, paused 96ms
01-14 21:08:28.092: D/dalvikvm(26585): GC_EXTERNAL_ALLOC freed 40K, 24% free 13579K/17735K, external 14641K/16689K, paused 102ms
01-14 21:08:28.212: D/dalvikvm(26585): GC_EXTERNAL_ALLOC freed 41K, 24% free 13574K/17735K, external 14641K/16689K, paused 103ms
01-14 21:08:28.212: W/dalvikvm(26585): threadid=17: thread exiting with uncaught exception (group=0x4001d5a0)
01-14 21:08:28.252: E/dalvikvm-heap(26585): 2529792-byte external allocation too large for this process.
01-14 21:08:28.252: E/dalvikvm(26585): Out of memory: Heap Size=17735KB, Allocated=13585KB, Bitmap Size=13902KB, Limit=32768KB
01-14 21:08:28.252: E/dalvikvm(26585): Trim info: Footprint=17735KB, Allowed Footprint=17735KB, Trimmed=1468KB
01-14 21:08:28.352: E/GraphicsJNI(26585): VM won't let us allocate 2529792 bytes

有人能帮我吗?谢谢

您是否尝试过
Manifest.xml
中的
android:largeHeap=“true”
?我还可以看到您正在处理位图,请使用类似以下方法的位图选项:

private Bitmap getBitmap(String path) {

Uri uri = getImageUri(path);
InputStream in = null;
try {
    final int IMAGE_MAX_SIZE = 1200000; // 1.2MP
    in = mContentResolver.openInputStream(uri);

    // Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(in, null, o);
    in.close();



    int scale = 1;
    while ((o.outWidth * o.outHeight) * (1 / Math.pow(scale, 2)) > 
          IMAGE_MAX_SIZE) {
       scale++;
    }
    Log.d(TAG, "scale = " + scale + ", orig-width: " + o.outWidth + ", 
       orig-height: " + o.outHeight);

    Bitmap b = null;
    in = mContentResolver.openInputStream(uri);
    if (scale > 1) {
        scale--;
        // scale to max possible inSampleSize that still yields an image
        // larger than target
        o = new BitmapFactory.Options();
        o.inSampleSize = scale;
        b = BitmapFactory.decodeStream(in, null, o);

        // resize to desired dimensions
        int height = b.getHeight();
        int width = b.getWidth();
        Log.d(TAG, "1th scale operation dimenions - width: " + width + ",
           height: " + height);

        double y = Math.sqrt(IMAGE_MAX_SIZE
                / (((double) width) / height));
        double x = (y / height) * width;

        Bitmap scaledBitmap = Bitmap.createScaledBitmap(b, (int) x, 
           (int) y, true);
        b.recycle();
        b = scaledBitmap;

        System.gc();
    } else {
        b = BitmapFactory.decodeStream(in);
    }
    in.close();

    Log.d(TAG, "bitmap size - width: " +b.getWidth() + ", height: " + 
       b.getHeight());
    return b;
} catch (IOException e) {
    Log.e(TAG, e.getMessage(),e);
    return null;
}

来源:

非常感谢,但我没有使用任何位图,而且HTC比第一款更强大。我认为有一些选择或类似的东西,我不知道确切的情况,我还想只分配2-3MB,我不认为Ram内存一定有问题