greendao -android.database.cursorwindowallocationexception:无法分配Cursorwindow< dbname>由于错误-12,大小104857600
因此,我基本上是在 greendao
生成的表中分析JSON并存储了〜3000行(无多媒体),并且在此功能中查询数据时会从上述错误中遇到上述错误:
@Synchronized
private fun checkGroupVisibility(
dependencyList: ArrayList<Long>,
dependencyType: String,
mInspectionId: Long,
isFromPhilosophyFlow: Boolean,
daoSession: DaoSession?,
string: String?
): Boolean {
var show = true
// Log.d("TAG", "checkGroupVisibility: lock testing 2"+string)
if (!DataSanityUtils.isListEmpty(dependencyList)) {
//check further in database if dependency question is answered
val inspectionReportCarParList:List<InspectionReportCarPart>? = daoSession?.inspectionReportCarPartDao?.queryBuilder()
?.where(InspectionReportCarPartDao.Properties.InspectionID.eq(mInspectionId))
?.where(InspectionReportCarPartDao.Properties.QuestionId.`in`(dependencyList))
?.list()
val inspectionReportCheckpointList:List<InspectionReportCheckpoint>? = daoSession?.inspectionReportCheckpointDao?.queryBuilder()
?.where(InspectionReportCheckpointDao.Properties.InspectionID.eq(mInspectionId))
?.where(InspectionReportCheckpointDao.Properties.ReportCheckpointVerdict.eq(CommonConstants.CHECKPOINT_VERDICT_NOT_OKAY))
?.list()
for (checkPointId in dependencyList) {
if (!isFromPhilosophyFlow && philosophyIdCheckPointMap.containsKey(checkPointId)) {
show = false
break
}
val isCarPartFound:InspectionReportCarPart?= inspectionReportCarParList?.find {
it.questionId==checkPointId
}
if (isCarPartFound==null) {
val isFound= inspectionReportCheckpointList?.find {
it.optionId==checkPointId
}
if (isFound == null) {
show = false
if (CommonConstants.DEPENDENCY_RELATION_AND.equals(
dependencyType,
ignoreCase = true
)
) {
break
}
} else if (CommonConstants.DEPENDENCY_RELATION_OR.equals(
dependencyType,
ignoreCase = true
)
) {
show = true
break
}
} else if (CommonConstants.DEPENDENCY_RELATION_OR.equals(
dependencyType,
ignoreCase = true
)
) {
show = true
break
}
}
}
// Log.d("TAG", "checkGroupVisibility: lock testing 3:"+string)
return show
}
当评估<<时,确切的错误正在出现。代码>检查ReportCarparlist (即代码中的第一个查询)。这是完整的stacktrace:
android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/data/user/0/com.example.visor/databases/report.json-db' of size 104857600 due to error -12.
at android.database.CursorWindow.nativeCreate(CursorWindow.java)
at android.database.CursorWindow.<init>(CursorWindow.java:139)
at android.database.CursorWindow.<init>(CursorWindow.java:120)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:202)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:149)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:142)
at de.greenrobot.dao.AbstractDao.loadAllFromCursor(AbstractDao.java:371)
at de.greenrobot.dao.AbstractDao.loadAllAndCloseCursor(AbstractDao.java:184)
at de.greenrobot.dao.InternalQueryDaoAccess.loadAllAndCloseCursor(InternalQueryDaoAccess.java:21)
at de.greenrobot.dao.query.Query.list(Query.java:130)
at de.greenrobot.dao.query.QueryBuilder.list(QueryBuilder.java:353)
at com.example.inspectionreport.utils.ReportUtils.checkGroupVisibility(ReportUtils.kt:31)
我也使用 de.greenrobot:greendao:2.0.0
此版本的Greendao。
我认为Greendao应该处理所有Cusrsor动作,并且在查询自己后关闭了光标。但是,Cursorwindow的尺寸仍然越来越大,应用程序崩溃了。请帮忙!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
光标窗口的大小有限(取决于Android版本,但最大为4MB)。 104857600是100MB,所以太大了。
Cursorwindow必须能够容纳1行或更多行,如果它不能容纳1行,那么您将会遇到这样的错误。
可以存储太大而无法检索的数据(这是图像的常见问题)。
处理如此大量数据的推荐方法是将数据(例如图像)存储在文件中,并将路径的路径或部分存储在数据库中。
其他评论
此问题不仅限于多媒体,这只是数据太大的一个例子。它可以是字符串(文本)数据。
这是一个显示此情况的示例(仅使用sqlite,greendao基本上只是一个包装器),该示例还包括一个替代方案的示例,该替代方案没有经历该问题,因为它将报告的可管理部分存储在单独的详细信息中相关表。
考虑以下代码: -
因此,有5个阶段每个阶段逐渐插入接近1MB的文本数据,沿着: -
....
每个阶段插入相同的数据(1MB,2MB .... 5MB)两次。
运行时,使用应用程序检查,然后: -
。
尝试读取V1_report表中的所有数据
如果 .sstatic.net/MH98b.png" rel="nofollow noreferrer">
现在,对于v2_report,没有问题: -
作为长文本数据已被拆分并放置在v2_details表中: -
可以清楚地看到这个问题(还可以证明数据存在并已成功地插入v1_report): -
尽管不准确(该示例已迅速组合在一起,看来我丢弃了一个字节/字符) 可以从两个V2中提取等效词表按: -
A Cursor Window has a restricted size (depends upon the Android Version but up to 4Mb). 104857600 is 100Mb, so way too large.
A CursorWindow has to be able to accommodate 1 or more rows, if it cannot hold 1 row then you will get such an error.
It is possible to store data that is too large to be retrieved (it is a common issue with images).
The recommended way of handling such large amounts of data is to store the data, such as an image, in a file and store the path or part of the path in the database.
Additional re the comment
The issue is not limited to multimedia, that is just an example of the data being too large. It could be String (TEXT) data.
Here's an example that shows the case (just using SQLite which greenDao is basically just a wrapper around), the example also includes an example of an alternative that does not experience the issue as it stores managable sections of the details of the report in a separate related table.
Consider the following code:-
So there are 5 stages each progressively inserting close to 1Mb of textual data along the lines of :-
....
Each stage inserts the same data (1Mb,2Mb .... 5Mb) twice.
When run, using App Inspection, then:-
If an attempt is made to read all of the data in the v1_report table then the CursorWindow size occurs:-
Now for v2_report, there is no issue :-
As the long textual data has been split and placed into the v2_details table :-
The issue can be clearly seeing (also proving that the data exists and has been inserted successfully into v1_report) by using the following:-
Although not accurate (the example has been quickly put together and it looks as though I've dropped a byte/character) the equivalent can be extracted from both the v2 tables as per:-