我有一部分代码,我使用此代码四次,但第六次,我的应用程序崩溃,我没有得到任何异常或错误代码。代码是:
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
我尝试使用:
try{
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
}catch (Exception e){
e.printStackTrace();
e.getMessage();
}catch (OutOfMemoryError o){
o.printStackTrace();
o.getMessage();
}catch (AssertionError a){
a.printStackTrace();
a.getMessage();
} catch ( Throwable t ){
t.printStackTrace();
t.getMessage();
}
但是没有发生。我在不同的决定中测试我的应用程序,在Sony Xperia Z3,Moto G,GenyMotion中使用不同的模拟器工作正常。
但是我的摩托罗拉Moto Max不适用。
日志控制台不显示错误,但打印一些代码:
--------- beginning of main
08-11 15:34:55.589 6258-6258/? E/Diag_Lib﹕ Diag_LSM_Init: Failed to open handle to diag driver, error = 2
08-11 15:35:00.638 6275-6275/? E/Diag_Lib﹕ Diag_LSM_Init: Failed to open handle to diag driver, error = 2
--------- beginning of system
08-11 15:35:00.723 817-1225/? V/AlarmManager﹕ send {ea59bfe, *alarm*:android.intent.action.TIME_TICK}
08-11 15:35:00.723 817-1225/? V/AlarmManager﹕ send {26ca6698, *alarm*:com.google.android.gms/.lockbox.LockboxAlarmReceiver}
08-11 15:35:00.748 817-817/? V/AlarmManager﹕ done {26ca6698, *alarm*:com.google.android.gms/.lockbox.LockboxAlarmReceiver} [26ms]
--------- beginning of crash
08-11 15:35:00.937 5910-5951/garagecoders.tecnoblinds.main A/libc﹕ Fatal signal 11 (SIGSEGV), code 2, fault addr 0xaf1f9000 in tid 5951 (AsyncTask #1)
08-11 15:35:00.946 817-817/? V/AlarmManager﹕ done {ea59bfe, *alarm*:android.intent.action.TIME_TICK} [224ms]
08-11 15:35:01.039 348-348/? I/DEBUG﹕ *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-11 15:35:01.039 348-348/? I/DEBUG﹕ Build fingerprint: 'motorola/quark_retla/quark_umts:5.0.2/LXG22.33-12.16/16:user/release-keys'
08-11 15:35:01.039 348-348/? I/DEBUG﹕ Revision: 'p4a0'
08-11 15:35:01.039 348-348/? I/DEBUG﹕ ABI: 'arm'
08-11 15:35:01.040 348-348/? I/DEBUG﹕ pid: 5910, tid: 5951, name: AsyncTask #1 >>> garagecoders.tecnoblinds.main <<<
08-11 15:35:01.040 348-348/? I/DEBUG﹕ signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xaf1f9000
08-11 15:35:01.068 348-348/? I/DEBUG﹕ r0 00000004 r1 af1f8ffc r2 024760c6 r3 f5d0f000
08-11 15:35:01.068 348-348/? I/DEBUG﹕ r4 b4873340 r5 000061cd r6 00000247 r7 000002fb
08-11 15:35:01.068 348-348/? I/DEBUG﹕ r8 00000248 r9 00004000 sl 00000000 fp 00003ff0
08-11 15:35:01.069 348-348/? I/DEBUG﹕ ip af1f9000 sp a0f3d078 lr 00000247 pc b5af8014 cpsr 200b0010
08-11 15:35:01.069 348-348/? I/DEBUG﹕ backtrace:
08-11 15:35:01.069 348-348/? I/DEBUG﹕ #00 pc 001bd014 /system/lib/libskia.so (NofilterDXExecutionBuffer::GenerateUpscaleProgram(int, int, int, int)+128)
08-11 15:35:01.069 348-348/? I/DEBUG﹕ #01 pc 001bdcfc /system/lib/libskia.so (NofilterDXExecutionBuffer::GenerateProgram(int, int, int, int)+92)
08-11 15:35:01.070 348-348/? I/DEBUG﹕ #02 pc 001bddf4 /system/lib/libskia.so (NfDXEBCache::prepareShaderProc32(int, int, int, int)+232)
08-11 15:35:01.070 348-348/? I/DEBUG﹕ #03 pc 001ba4d8 /system/lib/libskia.so (SkBitmapProcState::beginRect(int, int, int)+424)
08-11 15:35:01.070 348-348/? I/DEBUG﹕ #04 pc 001bade8 /system/lib/libskia.so (SkARGB32_Shader_Blitter::blitRect(int, int, int, int)+1244)
08-11 15:35:01.070 348-348/? I/DEBUG﹕ #05 pc 0010616b /system/lib/libskia.so
08-11 15:35:01.070 348-348/? I/DEBUG﹕ #06 pc 00106237 /system/lib/libskia.so (SkScan::FillIRect(SkIRect const&, SkRegion const*, SkBlitter*)+198)
08-11 15:35:01.070 348-348/? I/DEBUG﹕ #07 pc 00106307 /system/lib/libskia.so (SkScan::FillRect(SkRect const&, SkRegion const*, SkBlitter*)+136)
08-11 15:35:01.070 348-348/? I/DEBUG﹕ #08 pc 001063f7 /system/lib/libskia.so (SkScan::FillRect(SkRect const&, SkRasterClip const&, SkBlitter*)+56)
08-11 15:35:01.071 348-348/? I/DEBUG﹕ #09 pc 000e2037 /system/lib/libskia.so (SkDraw::drawRect(SkRect const&, SkPaint const&) const+258)
08-11 15:35:01.071 348-348/? I/DEBUG﹕ #10 pc 000e3513 /system/lib/libskia.so (SkDraw::drawBitmap(SkBitmap const&, SkMatrix const&, SkPaint const&) const+276)
08-11 15:35:01.071 348-348/? I/DEBUG﹕ #11 pc 000cb863 /system/lib/libskia.so (SkBitmapDevice::drawBitmapRect(SkDraw const&, SkBitmap const&, SkRect const*, SkRect const&, SkPaint const&, SkCanvas::DrawBitmapRectFlags)+530)
08-11 15:35:01.071 348-348/? I/DEBUG﹕ #12 pc 000db98f /system/lib/libskia.so (SkCanvas::internalDrawBitmapRect(SkBitmap const&, SkRect const*, SkRect const&, SkPaint const*, SkCanvas::DrawBitmapRectFlags)+210)
08-11 15:35:01.071 348-348/? I/DEBUG﹕ #13 pc 00093661 /system/lib/libandroid_runtime.so (android::SkiaCanvas::drawBitmap(SkBitmap const&, float, float, float, float, float, float, float, float, SkPaint const*)+58)
08-11 15:35:01.071 348-348/? I/DEBUG﹕ #14 pc 0008945d /system/lib/libandroid_runtime.so
08-11 15:35:01.071 348-348/? I/DEBUG﹕ #15 pc 0089eeff /system/framework/arm/boot.oat
有什么建议吗?
答案 0 :(得分:0)
我很确定你的设备内存不足,这就是为什么第6个createBitmap会使你的应用程序崩溃的原因。请尝试以下方法:
try{
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
} catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
这应该正确地为抛出的错误提供输出。让我知道输出,你可能需要手动调用System.gc()来处理你自己的所有垃圾收集。