2015-09-04 75 views
1

我有一個巨大的問題,我無法讓我的頭,基本上訪問我的android數據庫約130從數據庫中讀取後,它將此引發到logcat和活動結束。直到這一點,數據庫正在完美地讀取,並且無法看到每次都在此時失敗的原因。 09-04 16:45:31.754: E/SQLiteLog(4213): (14) cannot open file at line 27805 of [9491ba7d73] 09-04 16:45:31.754: E/SQLiteLog(4213): (14) os_unix.c:27805: (24) open(/data/data/com.boltgames.dev.cricketone/databases) - 09-04 16:45:31.758: E/SQLiteLog(4213): (14) cannot open file at line 30046 of [9491ba7d73] 09-04 16:45:31.758: E/SQLiteLog(4213): (14) os_unix.c:30046: (24) open(/data/data/com.boltgames.dev.cricketone/databases/Student.db-journal) - 09-04 16:45:31.758: E/SQLiteLog(4213): (14) cannot open file at line 30046 of [9491ba7d73] 09-04 16:45:31.758: E/SQLiteLog(4213): (14) os_unix.c:30046: (24) open(/data/data/com.boltgames.dev.cricketone/databases/Student.db-journal) - 09-04 16:45:31.758: E/SQLiteLog(4213): (14) statement aborts at 37: [SELECT DISTINCT _id, NAME, SURNAME, AGE, STAMINA, FITNESS, BOWLINGSKILL, BATTINGSKILL, OVERS, MAIDENS, BWLRUNS, WICKETS, ECONOMY, STRIKERATE, INNS, NOTOUT, BATRUNS, FIFTY, HUNDRED, FOU 09-04 16:45:31.759: E/SQLiteQuery(4213): exception: unable to open database file (code 14); query: SELECT DISTINCT _id, NAME, SURNAME, AGE, STAMINA, FITNESS, BOWLINGSKILL, BATTINGSKILL, OVERS, MAIDENS, BWLRUNS, WICKETS, ECONOMY, STRIKERATE, INNS, NOTOUT, BATRUNS, FIFTY, HUNDRED, FOURS, SIXES, DUCKS, CURBALLS, CURRUNS, CURFOURS, CURSIXES FROM Langley 09-04 16:45:31.759: D/AndroidRuntime(4213): Shutting down VM 09-04 16:45:31.760: E/AndroidRuntime(4213): FATAL EXCEPTION: main 09-04 16:45:31.760: E/AndroidRuntime(4213): Process: com.boltgames.dev.cricketone, PID: 4213 09-04 16:45:31.760: E/AndroidRuntime(4213): android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:845) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:144) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237) 09-04 16:45:31.760: E/AndroidRuntime(4213): at com.boltgames.dev.cricketlife.DatabaseHelper.getAllRows(DatabaseHelper.java:124) 09-04 16:45:31.760: E/AndroidRuntime(4213): at com.boltgames.dev.cricketlife.Play.SetData(Play.java:149) 09-04 16:45:31.760: E/AndroidRuntime(4213): at com.boltgames.dev.cricketlife.Play.SetPlayers(Play.java:134) 09-04 16:45:31.760: E/AndroidRuntime(4213): at com.boltgames.dev.cricketlife.Play.PlayOneRun(Play.java:277) 09-04 16:45:31.760: E/AndroidRuntime(4213): at com.boltgames.dev.cricketlife.Play$1.onClick(Play.java:249) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.view.View.performClick(View.java:4780) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.view.View$PerformClick.run(View.java:19866) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.os.Handler.handleCallback(Handler.java:739) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.os.Handler.dispatchMessage(Handler.java:95) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.os.Looper.loop(Looper.java:135) 09-04 16:45:31.760: E/AndroidRuntime(4213): at android.app.ActivityThread.main(ActivityThread.java:5254) 09-04 16:45:31.760: E/AndroidRuntime(4213): at java.lang.reflect.Method.invoke(Native Method) 09-04 16:45:31.760: E/AndroidRuntime(4213): at java.lang.reflect.Method.invoke(Method.java:372) 09-04 16:45:31.760: E/AndroidRuntime(4213): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 09-04 16:45:31.760: E/AndroidRuntime(4213): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 不能打開文件在行27805

這是我訪問代碼數據庫

cursor = mydb.getAllRows(gamemanager.hometeam); 
    cursor.moveToFirst(); 
    startManagingCursor(cursor); 
    String[] fromfieldnames = new String[]{DatabaseHelper.COL_2, DatabaseHelper.COL_3, 
      DatabaseHelper.COL_23, DatabaseHelper.COL_24}; 
    int[] toviewids = new int[]{R.id.scorecplayer, R.id.scorecsur, R.id.scorecballs, R.id.scorecruns}; 
    mycursoradaptor = new SimpleCursorAdapter(this, R.layout.scorecardbat, 
      cursor, fromfieldnames, toviewids); 
    batting.setAdapter(mycursoradaptor); 
    totruns.setText(Long.toString(totalruns)); 
    ballComplete = true; 
    oneballnorun.setVisibility(View.VISIBLE); 

請幫助:(

M.

編輯: - 增加了數據庫腳本的代碼

SQLiteDatabase db = this.getWritableDatabase(); 
    // Return all data in database 
    String where = null; 
    cursor = db.query(true, teamname, ALL_KEYS, where, null, null, null, null, null); 
    Log.i("Success2", "Data is accessed"); 
    if (cursor != null){ 
     Log.i("Cursor3", cursor.toString()); 
     cursor.moveToFirst(); 

    } 
    if(cursor == null){ 
     Log.i("Error!!!", "No Data!"); 
    } 
    return cursor; 
+0

原諒我,但爲什麼downvote? '大約130次讀取'後' – Marca

+0

'。你認爲什麼是「閱讀」? – greenapps

+0

好的,例如我每次玩「球」時都會運行上面的腳本。之後約。應用程序失敗的139腳本和146腳本運行。到目前爲止,我已經做了一些調試,直到光標創建的地方纔發現沒有錯誤。我將爲你添加上面的代碼。因此,在上述時間後,運行良好,光標或數據庫變得不知何故 – Marca

回答

0
mydb.cursor.close(); 
    Log.i("Success1", "Access Started"); 
    try { 
     cursor = mydb.getAllRows(gamemanager.hometeam); 
    }catch (Throwable ex) { 
     Log.i("Error", "Maybe retrying i dont know"); 
    } 
    Log.i("Success!4", "Cursor is Active!"); 
    startManagingCursor(cursor); 
    Log.i("Success!5", "Cursor is being managed"); 
    String[] fromfieldnames = new String[]{DatabaseHelper.COL_2, DatabaseHelper.COL_3, 
      DatabaseHelper.COL_23, DatabaseHelper.COL_24}; 
    Log.i("Success6", "Stage1"); 
    int[] toviewids = new int[]{R.id.scorecplayer, R.id.scorecsur, R.id.scorecballs, R.id.scorecruns}; 
    Log.i("Success7", "Stage2"); 
    mycursoradaptor = new SimpleCursorAdapter(this, R.layout.scorecardbat, 
      cursor, fromfieldnames, toviewids); 
    Log.i("Success8", "Stage3"); 
    batting.setAdapter(mycursoradaptor); 
    Log.i("Success9", "Stage4"); 
+0

在函數的開頭插入了close,因爲你可以看到很多調試哈哈可能看起來更混亂,更專業的眼睛:) – Marca