我的应用程序不断崩溃,SQLite数据库泄漏错误

时间:2017-05-01 08:24:47

标签: java android sqlite android-sqlite

我目前正在开发一个大学项目,这是一个飞镖计算器应用程序,我不断收到数据库泄漏错误,即使我认为我在使用它后关闭所有数据库和游标。我也得到了一个“W / IdleConnectionHandler:删除一个从未存在过的连接!”程序开头的错误。

我的logcat有这些错误:

mat.temp1[i,j] = mean(mat.temp[max(1,i-1):min(nrow(mat.temp),i+1),
                               max(1,j-1):min(ncol(mat.temp),j+1)])

05-01 08:33:47.801 9504-9581/? W/IdleConnectionHandler: Removing a connection that never existed!
05-01 08:43:46.141 9504-9581/? W/IdleConnectionHandler: Removing a connection that never existed!

我的数据库帮助程序类如下所示:

05-01 09:08:06.841 4858-4866/? W/SQLiteConnectionPool: A SQLiteConnection object for database '+data+user+0+com_google_android_gms+databases+auto_complete_suggestions_db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-01 09:08:06.841 4858-4866/? W/SQLiteConnectionPool: A SQLiteConnection object for database '+data+user+0+com_google_android_gms+databases+help_responses_db_18' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-01 09:08:06.841 4858-4866/? W/SQLiteConnectionPool: A SQLiteConnection object for database '+data+user+0+com_google_android_gms+databases+metrics_db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

我在这里面临严重的时间压力,所以任何帮助都会非常感激!`

1 个答案:

答案 0 :(得分:0)

在获取记录之前关闭了光标。

您需要在关闭Cursor

之前将其添加到您的代码中
res.moveToFirst(); //move Cursor to first record 
while (cur.isAfterLast() == false) {  // while Cursor not point to last record 
Log.v("YOURTAG",  cur.getString("yourString")); // get your data
//ToDo save your data
cur.moveToNext();
}
// ToDo return your data

现在你可以关闭光标