In addition, I believe that too many cursors and, therefore, open's, can also lead to the same “incapable of opening a database file error”. (in the following code there are 507 lines in shoplistcursor , so there were more than 1,500 cursors used / reused in total)
I received the same message. In accordance with: -
10-29 19:57:00.901 12845-12845/mjt.shopper E/SQLiteLog: (14) cannot open file at line 30046 of [9491ba7d73] 10-29 19:57:00.901 12845-12845/mjt.shopper E/SQLiteLog: (14) os_unix.c:30046: (24) open(/data/data/mjt.shopper/databases/Shopper-journal) - 10-29 19:57:00.901 12845-12845/mjt.shopper E/SQLiteLog: (14) cannot open file at line 30046 of [9491ba7d73] 10-29 19:57:00.901 12845-12845/mjt.shopper E/SQLiteLog: (14) os_unix.c:30046: (24) open(/data/data/mjt.shopper/databases/Shopper-journal) - 10-29 19:57:00.901 12845-12845/mjt.shopper E/SQLiteLog: (14) statement aborts at 24: [SELECT * FROM productusage WHERE productailseref = 60 AND productproductref = 75 ;] unable to open database file 10-29 19:57:00.902 12845-12845/mjt.shopper E/SQLiteQuery: exception: unable to open database file (code 14); query: SELECT * FROM productusage WHERE productailseref = 60 AND productproductref = 75 ; 10-29 19:57:00.902 12845-12845/mjt.shopper D/AndroidRuntime: Shutting down VM 10-29 19:57:00.903 12845-12845/mjt.shopper E/AndroidRuntime: FATAL EXCEPTION: main
The code that was in the error was: -
SQLiteDatabase db = getWritableDatabase(); Cursor shoplistcursor = getAllRowsFromTable(SHOPLIST_TABLE_NAME); Cursor productcsr; Cursor aislecsr; Cursor prdusecsr; while(shoplistcursor.moveToNext()) { productcsr = getProductFromProductId(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_PRODUCTREF))); aislecsr = getAisleFromAisleId(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_AISLEREF))); prdusecsr = getProductUsage(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_AISLEREF)), shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_PRODUCTREF))); if (productcsr.getCount() < 1 | aislecsr.getCount() < 1 | prdusecsr.getCount() < 1) { deleteShopListEntry(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_ID))); } if(shoplistcursor.isLast()) { prdusecsr.close(); aislecsr.close(); productcsr.close(); } } shoplistcursor.close(); db.close(); }
The treatment was to close the cursors at each iteration. In accordance with: -
SQLiteDatabase db = getWritableDatabase(); Cursor shoplistcursor = getAllRowsFromTable(SHOPLIST_TABLE_NAME); Cursor productcsr; Cursor aislecsr; Cursor prdusecsr; while(shoplistcursor.moveToNext()) { productcsr = getProductFromProductId(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_PRODUCTREF))); aislecsr = getAisleFromAisleId(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_AISLEREF))); prdusecsr = getProductUsage(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_AISLEREF)), shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_PRODUCTREF))); if (productcsr.getCount() < 1 | aislecsr.getCount() < 1 | prdusecsr.getCount() < 1) { productcsr.close(); aislecsr.close(); prdusecsr.close(); deleteShopListEntry(shoplistcursor.getLong(shoplistcursor.getColumnIndex(SHOPLIST_COLUMN_ID))); } else { productcsr.close(); aislecsr.close(); prdusecsr.close(); } } shoplistcursor.close(); db.close(); }
source share