Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Android . unable to open database file

I found a lot of question about this problem, but i can't fix it. I have a sqlite db in assets folder:

assets/data/data/{package_name}/databases/mydb.db

I can open database and read data before change one table structure. I try to uninstall the app and reinstall again, but i get the same exception.

What can i do now?

Thanks in advance

EDIT

// The Android's default system path of your application database.
private static String DB_PATH = "/data/data/{mypagackename}/databases/";

private static String DB_NAME = "mydb.db";

Open database (Before change table structure, adding some fields, it doesn't work)

public void openDataBase() throws SQLException {

    // Open the database
    String myPath = DB_PATH + DB_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READONLY);

}
like image 362
jzafrilla Avatar asked Jul 26 '12 14:07

jzafrilla


People also ask

Why SQLite Cannot open database file?

If SQLite is unable to open the database file, this means that the SQLite database you are trying to open is corrupted. There are various causes of corruption, such as file overwrite issues, file locking issues, database synchronization failures, storage media failures, and many more.


1 Answers

Look at this tutorial

It Explains how to work with preloaded database. Basically you can't use database right from the assets, you have to copy it over into internal data storage first and open it from there

like image 162
Maxim Avatar answered Oct 07 '22 13:10

Maxim