我正在 Android 4.0+ 上测试一个应用程序,它运行良好。在 2.2/2.3 上,我一直遇到SQLlite
游标问题。如果这种情况发生在应用程序启动时的 90% 时,这很奇怪。我无法解释为什么它有时会起作用。
这是部分LogCat
:
05-01 20:02:30.341: E/Cursor(369): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.---.---/databases/cats.db, table = trending_watching, query = SELECT _id, item_id, item, review, review_id, cat, user, url FROM trending_watching
05-01 20:02:30.341: E/Cursor(369): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
这是发生问题的地方:
在启动画面中,我从 MySQL 中获取值并将它们放入两个不同的 SQLlite 表中。我可以验证该表是否正在填充数据。启动画面退出。
下一个 Activity 获取两个 SQLLite 表并获取如下数据:
// Open Database
watchItemIdList = datasource
.getWatchStrings(MySQLiteHelper.COLUMN_TREND_WATCH_ITEM_ID);
watchUsers = datasource
.getWatchStrings(MySQLiteHelper.COLUMN_TREND_WATCH_USER);
watchCats = datasource
.getWatchStrings(MySQLiteHelper.COLUMN_TREND_WATCH_CAT);
watchReviews = datasource
.getWatchStrings(MySQLiteHelper.COLUMN_TREND_WATCH_REVIEW);
watchReviewId = datasource
.getWatchStrings(MySQLiteHelper.COLUMN_TREND_WATCH_REVIEW_ID);
watchItems = datasource
.getWatchStrings(MySQLiteHelper.COLUMN_TREND_WATCH_ITEM);
watchUrl = datasource
.getWatchStrings(MySQLiteHelper.COLUMN_TREND_WATCH_URL);
// Close database
它在这里获取数据:
public List<String> getWatchStrings(String dbColumn) {
Cursor cursor = database.query(MySQLiteHelper.TABLE_WATCHING_REVIEWS,
allTrendWatchingColumns, null, null, null, null, null);
List<String> array = new ArrayList<String>();
while (cursor.moveToNext()) {
String uname = cursor.getString(cursor.getColumnIndex(dbColumn));
array.add(uname);
}
return array;
}
该应用程序不断崩溃,我相信LogCat
这一点:
Cursor cursor = database.query(MySQLiteHelper.TABLE_WATCHING_REVIEWS,
allTrendWatchingColumns, null, null, null, null, null);