10

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);

}
6
  • What exception? What code you are trying? Commented Jul 26, 2012 at 14:12
  • You are modifying the table structure within program or before and save new configuration to the assets folder? Commented Jul 26, 2012 at 14:13
  • I'm modifying table structure with sourceforge.net/projects/sqlitebrowser/files/latest/download I save the file and replace it in assets folder. what i'm doing wrong? Commented Jul 26, 2012 at 14:14
  • Please consider using SQLiteAssetHelper as a debugged solution for packaging a database with your app and unpacking it on first use: github.com/jgilfelt/android-sqlite-asset-helper Commented Jul 26, 2012 at 14:16
  • 1
    No it's not gonna work this way, db should be in internal device memory. data/data/your.package.name/your.db not in assets. Commented Jul 26, 2012 at 14:24

2 Answers 2

12

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

Sign up to request clarification or add additional context in comments.

Comments

3

Instead of hard coded DB_PATH (no longer work in JB), I would recommend always go with Android inbuilt API method,

mContext.getDatabasePath(DATABASE_NAME).getPath();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.