我有一个应用程序,可以在特定月份内检索日志(保存在sqlite db中),并有两个按钮来浏览一年中的几个月。当我运行它时它工作正常,但是当我浏览几个月后,它会在几次导航后出错。任何想法先生?
这是我得到的错误
02-04 23:35:36.965: E/SQLiteLog(7719): (14) cannot open file at line 30046 of [9491ba7d73]
02-04 23:35:36.965: E/SQLiteLog(7719): (14) os_unix.c:30046: (24) open(/data/data/com.example.adah/databases/ADAHdb-journal) -
02-04 23:35:36.965: E/SQLiteLog(7719): (14) cannot open file at line 30046 of [9491ba7d73]
02-04 23:35:36.965: E/SQLiteLog(7719): (14) os_unix.c:30046: (24) open(/data/data/com.example.adah/databases/ADAHdb-journal) -
02-04 23:35:36.965: E/SQLiteLog(7719): (14) statement aborts at 15: [SELECT * FROM DailyLogs WHERE OutletID='6' AND Date='2016/02/14'] unable to open database file
02-04 23:35:36.965: E/SQLiteQuery(7719): exception: unable to open database file (code 14); query: SELECT * FROM DailyLogs WHERE OutletID='6' AND Date='2016/02/14'
02-04 23:35:36.965: D/AndroidRuntime(7719): Shutting down VM
02-04 23:35:36.965: E/AndroidRuntime(7719): FATAL EXCEPTION: main
02-04 23:35:36.965: E/AndroidRuntime(7719): Process: com.example.adah, PID: 7719
02-04 23:35:36.965: E/AndroidRuntime(7719): android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:845)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:144)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237)
02-04 23:35:36.965: E/AndroidRuntime(7719): at DatabaseClasses.AccountDAO.getDLog(AccountDAO.java:427)
02-04 23:35:36.965: E/AndroidRuntime(7719): at com.example.adah.GraphHistory.getSample1(GraphHistory.java:229)
02-04 23:35:36.965: E/AndroidRuntime(7719): at com.example.adah.GraphHistory.populate(GraphHistory.java:116)
02-04 23:35:36.965: E/AndroidRuntime(7719): at com.example.adah.GraphHistory$2.onClick(GraphHistory.java:81)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.view.View.performClick(View.java:4756)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.view.View$PerformClick.run(View.java:19761)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.os.Handler.handleCallback(Handler.java:739)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.os.Handler.dispatchMessage(Handler.java:95)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.os.Looper.loop(Looper.java:135)
02-04 23:35:36.965: E/AndroidRuntime(7719): at android.app.ActivityThread.main(ActivityThread.java:5253)
02-04 23:35:36.965: E/AndroidRuntime(7719): at java.lang.reflect.Method.invoke(Native Method)
02-04 23:35:36.965: E/AndroidRuntime(7719): at java.lang.reflect.Method.invoke(Method.java:372)
02-04 23:35:36.965: E/AndroidRuntime(7719): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-04 23:35:36.965: E/AndroidRuntime(7719): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
这里是重复调用的代码,用于从sqlite db中检索数据:
public String getDLog(String Date, int OutletID) {
// TODO Auto-generated method stub
SQLiteDatabase db= helper.getReadableDatabase();
String query="SELECT * FROM DailyLogs WHERE OutletID='"+OutletID+"' AND Date='"+Date+"'";
Cursor c=db.rawQuery(query, null);
if(c.moveToFirst())
{
String data=c.getString(c.getColumnIndex("Data"));
db.close();
return data;
}
else
{
db.close();
return "000000000000000000000000000000000000000000000000";
}
}