问题
I have a part of code, i use this code four times, but the the sixth time, my application crash , i don't get any Exception or error code. The code is:
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
I try to use:
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();
}
But nothings happen. I test my application in diferent dispositives, works fine in a Sony Xperia Z3, Moto G , GenyMotion with different simulators.
But dont works in my Motorola Moto Max.
The log console dont shows an error, but print some codes:
--------- 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
any suggestions ?
回答1:
I am pretty sure you are running out of memory for your device, which is why the 6th createBitmap is going to crash your application. Try the following:
try{
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
} catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
This should properly give output for errors that are thrown. Let me know the output, you might need to manually call System.gc() to handle all the garbage collection youself.
Read this: Displaying Bitmaps Efficiently
来源:https://stackoverflow.com/questions/31951736/cant-catch-java-android-exception-with-try-catch-createbitmap