首页 > 解决方案 > Android cursor = mydatabase.rawQuery 中断应用程序 - 信号 11

问题描述

我知道以前在这里提出过类似的问题,但这让我难以置信。我已经研究过这个错误,当你引用数组的某个部分超出其边界或其他东西时,它似乎主要弹出,但只有当我在 API 低于 23 的虚拟设备上运行应用程序时才会出现此错误。机器它失败的是 API 22 上的 Galaxy Nexus,但它在 API 22 的 Nexus 4 上也失败了。我也在 API 23 的虚拟 Nexus 4 上对其进行了测试,它可以工作,上面的每个 API 也可以工作。我希望我的最低 SDK 更低,但在我解决这个问题之前这是不可能的。下面是一些代码,可以帮助天才们了解是什么让我发疯。

(光标结果集是全局设置的,但没有什么区别) resultSet = mydatabase.rawQuery("SELECT * FROM words WHERE" + allowRepeats + " frequency >= 0 ORDER BY RANDOM() LIMIT 1",null);- 无论我做什么,这条线都会中断。

此代码呈现到"SELECT * FROM words WHERE solved < 1 AND frequency >= 0 ORDER BY RANDOM() LIMIT 1"并且此代码适用于 22 以上的每个 API,但是在 22 上运行时出现错误“A/libc:致命信号 11 (SIGSEGV),代码 1,tid 27273 (ics.choicewords) 中的故障地址 0x2c”

关于我尝试过的一些注释:我确保数据库确实存在,就像我说的它适用于其他 API

我尝试将光标设置为 null 并返回空字符串作为结果而不是任何数据,这工作正常但当然不是一个选项

rawQuery 在循环 4 次的循环中运行,但将其取出并仅运行该单行一次仍然会因相同的错误而中断

错误日志:

I/art: Rejecting re-init on previously-failed class java.lang.Class<Tz>
    Rejecting re-init on previously-failed class java.lang.Class<Tz>
W/cr_media: Requires BLUETOOTH permission
E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
D/: HostConnection::get() New Host Connection established 0xae9b0880, tid 5080
E/chromium: [ERROR:gl_surface_egl.cc(411)] eglChooseConfig failed with error EGL_SUCCESS
D/EGL_emulation: eglCreateContext: 0xae9bf7c0: maj 2 min 0 rcv 2
I/Ads: This request is sent from a test device.
D/EGL_emulation: eglMakeCurrent: 0xae9bf7c0: ver 2 0 (tinfo 0xae839eb0)
E/chromium: [ERROR:gl_surface_egl.cc(411)] eglChooseConfig failed with error EGL_SUCCESS
I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:21001
    Selected remote version of com.google.android.gms.ads.dynamite, version >= 21001
V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
I/art: Background partial concurrent mark sweep GC freed 2186(176KB) AllocSpace objects, 1(12KB) LOS objects, 33% free, 7MB/11MB, paused 9.052ms total 67.508ms
W/Ads: Invoke Firebase method getInstance error.
    The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this device.
D/EGL_emulation: eglCreateContext: 0xaea6c640: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xaea6c640: ver 2 0 (tinfo 0xae839eb0)
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x2c in tid 4979 (ics.choicewords)```

标签: javaandroidsqliteandroid-studio

解决方案


我很久以前就修复了这个错误,所以我不完全确定如何,但回顾我的旧代码,似乎在没有与查询匹配的结果时创建了错误。后来我通过检查 resultSet 计数来解决这个问题,如果它小于 1,我将 resultSet 替换为一组任意值,我的应用程序可以理解这意味着没有结果。这解决了问题!


推荐阅读