Я хочу выполнить некоторую работу в слушателе кнопки onClick, но он завершился с ошибкой после завершения метода onClick ()
Во-первых, я думаю, что в OnClickListener не может быть слишком много работы. поэтому я делаю ту же работу в новом потоке, но сбой все еще существует.
Это OnClickListener, установленный для кнопки:
stopButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CloseDevice();
mTxtStatus.setText("close device successfully!");
new Thread(new Runnable() {
@Override
public void run() {
if (mBufImage == null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mTxtReport.setText("capture failed");
}
});
return;
}
final byte reshapedImg[] = reshape(1);
byte centerImage[] = addCenterPoint(reshapedImg, 256,256);
if (centerImage == null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mTxtStatus.setText("run: locate failed");
}
});
return;
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
mTxtStatus.setText("run:locate success! ");
}
});
}
final byte recropedImg [] = recropImg(reshapedImg,256,256);
runOnUiThread(new Runnable() {
@Override
public void run() {
Bitmap bitmap = ToolUtils.renderCroppedGreyScaleBitmap(recropedImg, 175, 175);
mImgView.setImageBitmap(bitmap);
}
});
double feature [][] = ju.extractFeature(recropedImg,175,175);
printarr(feature);
}
}).run();
}
В этом коде.
double feature [][] = ju.extractFeature(recropedImg,175,175);
эта функция является родным методом. и следующая строка
printarr(feature);
распечатает массив в logcat.
Logcat показывает вывод printarr () до его сбоя. поэтому я уверен, что метод onClick () завершен, но он потерпел крах!
Я сомневаюсь, что это сбой в моем родном методе, потому что сбой произойдет, только если я добавлю нативный метод. Но обратная трассировка показывает, что это не имеет значения с моей родной библиотекой:
05-24 15:35:37.329 5792-5792/com.example.wangzh.normaltest I/Choreographer: Skipped 65 frames! The application may be doing too much work on its main thread.
05-24 15:35:37.337 5792-5810/com.example.wangzh.normaltest A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x40bcf39a3c0aa84c in tid 5810 (RenderThread), pid 5792 (ngzh.normaltest)
05-24 15:35:37.395 5831-5831/? I/crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone
05-24 15:35:37.396 2752-2752/? I//system/bin/tombstoned: received crash request for pid 5810
05-24 15:35:37.396 5831-5831/? I/crash_dump64: performing dump of process 5792 (target tid = 5810)
05-24 15:35:37.408 5831-5831/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-24 15:35:37.409 5831-5831/? A/DEBUG: Build fingerprint: 'Android/hikey960/hikey960:9/PQ1A.190105.004/wangzh05142144:userdebug/test-keys'
Revision: '0'
ABI: 'arm64'
pid: 5792, tid: 5810, name: RenderThread >>> com.example.wangzh.normaltest <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x40bcf39a3c0aa84c
x0 00000070508ccc40 x1 00000070367ed330 x2 0000007050837bb0 x3 000000704a09e838
x4 0000000000000000 x5 0000000000000000 x6 0000007036293948 x7 0000000044730000
x8 40bcf39a3c0aa7ec x9 29ffcb3e9a9df1e0 x10 00000070d2ad7000 x11 0000000000000000
x12 0000000000000000 x13 00000000000000ff x14 00000000000007b0 x15 0000000000000000
x16 00000070d2c5a650 x17 00000070d295b9d0 x18 0000007036295c00 x19 0000007036293948
x20 0000007050837bb0 x21 00000070367ed330 x22 000000704a0a6780 x23 0000000000000000
x24 0000000000000000 x25 000000704a09e838 x26 000000703629f588 x27 0000000000003815
x28 0000000000000000 x29 00000070362938e0
sp 0000007036293800 lr 00000070d292bfdc pc 00000070d292c178
05-24 15:35:37.451 5831-5831/? A/DEBUG: backtrace:
#00 pc 000000000046f178 /system/lib64/libhwui.so (_ZL23skpaint_to_grpaint_implP9GrContextRK16GrColorSpaceInfoRK7SkPaintRK8SkMatrixPNSt3__110unique_ptrI19GrFragmentProcessorNSA_14default_deleteISC_EEEEP11SkBlendModeP7GrPaint.llvm.2395171566+592)
#01 pc 00000000002ada14 /system/lib64/libhwui.so (SkGpuDevice::drawOval(SkRect const&, SkPaint const&)+188)
#02 pc 000000000049c300 /system/lib64/libhwui.so (SkCanvas::onDrawOval(SkRect const&, SkPaint const&)+392)
#03 pc 000000000049ea38 /system/lib64/libhwui.so (SkCanvas::drawCircle(float, float, float, SkPaint const&)+104)
#04 pc 000000000045b0d0 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+352)
#05 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#06 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#07 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#08 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#09 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#10 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#11 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#12 pc 000000000047e1a4 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::EndReorderBarrierDrawable::onDraw(SkCanvas*)+252)
#13 pc 000000000045b0d0 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+352)
#14 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#15 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#16 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#17 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#18 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#19 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#20 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#21 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#22 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#23 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#24 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#25 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#26 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#27 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#28 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#29 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#30 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#31 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#32 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#33 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#34 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#35 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#36 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#37 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#38 pc 000000000045b88c /system/lib64/libhwui.so (SkLiteDL::draw(SkCanvas*) const+196)
#39 pc 000000000043be7c /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+292)
#40 pc 000000000043c244 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+252)
#41 pc 000000000045b004 /system/lib64/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+148)
#42 pc 00000000000fd9a0 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaPipeline::renderFrameImpl(android::uirenderer::LayerUpdateQueue const&, SkRect const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, bool, bool, android::uirenderer::Rect const&, SkCanvas*)+424)
#43 pc 00000000004803c8 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaPipeline::renderFrame(android::uirenderer::LayerUpdateQueue const&, SkRect const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, bool, bool, android::uirenderer::Rect const&, sk_sp<SkSurface>)+136)
#44 pc 000000000047f5d4 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaOpenGLPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::FrameBuilder::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, bool, android::uirenderer::BakedOpRenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::Re
#45 pc 0000000000108028 /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw()+192)
#46 pc 00000000004844dc /system/lib64/libhwui.so (_ZNSt3__110__function6__funcIZN7android10uirenderer12renderthread13DrawFrameTask11postAndWaitEvE3$_0NS_9allocatorIS6_EEFvvEEclEv$c303f2d2360db58ed70a2d0ac7ed911b+644)
#47 pc 000000000043adc8 /system/lib64/libhwui.so (android::uirenderer::WorkQueue::process()+168)
#48 pc 000000000011575c /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+244)
#49 pc 000000000000fb80 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+280)
#50 pc 0000000000083194 /system/lib64/libc.so (__pthread_start(void*)+36)
#51 pc 00000000000233bc /system/lib64/libc.so (__start_thread+68)
05-24 15:35:37.834 2752-2752/? E//system/bin/tombstoned: Tombstone written to: /data/tombstones/tombstone_15
Может ли кто-нибудь дать совет? Все ценится! Заранее спасибо.