Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unknown error (code 14): Could not open database

Tags:

android

sqlite

I have a working app which employs a database and SQLiteAssetHelper. The database file (sql.sqlite) is zipped (sql.sqlite.zip) and put in the assets/databases folder.

The program works perfectly well. And when run for a second/third/fourth... time it starts up quickly. But if I do a "force stop" followed by a "clear data" then run it again, then when I run it (viewing logs) I see an error "unknown error (code 14): Could not open database"... but then I wait a few seconds and it all loads and works perfectly.

The log is as follows:

W/SQLiteAssetHelper(18393): could not open database SQL.sqlite - unknown error (code 14): Could not open database
W/SQLiteAssetHelper(18393): copying database from assets...
W/SQLiteAssetHelper(18393): extracting file: 'sql.sqlite'...
W/SQLiteAssetHelper(18393): database copy complete
I/SQLiteAssetHelper(18393): successfully opened database SQL.sqlite

So it looks like it somehow tried to find the database, failed, crashed, and then repaired itself. So my question is, how could I have avoided the clumsy start and the several seconds of delay?

EDIT: My first reference to the database in my code is...

public class Globals extends Application
{
    Custom_SQLiteAssetHelper db;   
    public void onCreate()
    {
        super.onCreate();
        db = new Custom_SQLiteAssetHelper(this);
        cursor = db.get_first_species_common_name();

and I have...

public class Custom_SQLiteAssetHelper extends SQLiteAssetHelper
{
    public Custom_SQLiteAssetHelper(Context context)
    {
        super(context, "SQL.sqlite", null, 1);  
    }
    public Cursor get_first_species_common_name()
    {
        SQLiteDatabase db = getReadableDatabase();
        SQLiteQueryBuilder querything = new SQLiteQueryBuilder();
            // etc...
like image 485
Mick Avatar asked Oct 07 '13 15:10

Mick


1 Answers

Finally I have found the answer. you should use the newer version of SQLiteAssetHelper

like image 169
Arash Khoeini Avatar answered Nov 18 '22 15:11

Arash Khoeini