aronpolak
aronpolak

Reputation: 9

Android Studio - SQLite database file location

I copied project from one place to another computer. I exported project using File>Export>Export to Zip file I opened project and try to run but there is information E/SQLiteLog: (1) no such table: .... File with SQLite database is in Project main folder. I try to find place in project where I can manually define path to database file. In this project I want to have database file in different location then default.

Can any one tell me how to manually define database file location for the project in android studio?

Upvotes: 0

Views: 448

Answers (1)

MikeT
MikeT

Reputation: 56938

Can any one tell me how to manually define database file location for the project in android studio?

You can use the SQLiteDatabase's openDatabase or openOrCreateDatabase methods where you can specify the path or file.

See https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#openDatabase(java.lang.String,%20android.database.sqlite.SQLiteDatabase.CursorFactory,%20int)

File with SQLite database is in Project main folder

If you have a pre-existing/pre-populated database that you want to be provided as part of the package then this should be supplied as an asset (typically in the assets folder or assets/databases folder) which would need to be copied to a suitable location by the App before opening the database if the database does not exist.

Upvotes: 1

Related Questions