使用try-catch,createBitmap无法捕获Java(Android)异常 [英] Can't catch Java (Android) Exception with try-catch , createBitmap
问题描述
我有一部分代码,我四次使用此代码,但是第六次,我的应用程序崩溃了,我没有任何异常或错误代码。代码是:
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);
我尝试使用:
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上运行良好。
But nothings happen. I test my application in diferent dispositives, works fine in a Sony Xperia Z3, Moto G , GenyMotion with different simulators.
但是在我的Motorola Moto Max中不起作用。
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
有什么建议吗?
推荐答案
我很确定您的设备内存不足,这就是第6个createBitmap会使您的设备崩溃的原因应用。请尝试以下操作:
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();
}
这应该正确地输出抛出的错误。让我知道输出,您可能需要手动调用System.gc()来处理您自己的所有垃圾收集。
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.
请阅读以下内容:有效显示位图
这篇关于使用try-catch,createBitmap无法捕获Java(Android)异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!