No such table android_metadata, what's the problem?

AndroidSqlite

Android Problem Overview


I am copying a pre-existing database to /data/data/packagename/databases using code learned from using-your-own-sqlite-database-in-android-applications

After copying, I recieve the following log message on opening the database:

No such table android_metadata

Do I need to create a table named android_metadata? And what the values do i need insert into this database table

Thanks very much

Android Solutions


Solution 1 - Android

Actually, with a bit more reading, I have discovered that I need to use the SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when calling SQLiteDatabase.openDatabase() - this no longer causes the problem.

Solution 2 - Android

Use

SQLiteDatabase.openDatabase(dbPath, null,SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.CREATE_IF_NECESSARY);

or

SQLiteDatabase.openDatabase(dbPath, null,SQLiteDatabase.OPEN_READWRITE);

Solution 3 - Android

It seems that for some reason android requires every database to have a table called android_metadata that includes at least one locale. The reigndesign blog you mentioned tells you how to create the table and prefill it with a locale.

Check if your database contains this table and if the table has some content.

Solution 4 - Android

When you copy database from your assets directory for example, then you must have android_metadata table created in it already. This table should have two columns:

_id = an integer value
locale = en

Solution 5 - Android

I am already using as given in that link for a long time..

It works.. Checkout your DB again the table created or not ?

I prefer to install SQLite Manager plugin in firefox for sqlite database operation.. after completing all process as mentioned in the same link..

Checkout http://www.devx.com/wireless/Article/40842/1954.

It contains all database operations.

Solution 6 - Android

it might also just be file permissions - the error message is misleading. first you need to find out the user id of the app (this is assuming you have root access):

$ adb shell grep <packagename> /data/system/packages.xml

output should look like:

<package name="com.fsck.k9" codePath="/data/app/com.fsck.k9-1.apk" 
nativeLibraryPath="/data/data/com.fsck.k9/lib" 
flags="0" ft="1306ecac340" it="1306ecac9d2" ut="1306ecac9d2"
version="14001" userId="10002">

userId here is 10002.

then fix permissions:

$ adb shell chown -R 10002:10002 /data/data/<packagename>

Solution 7 - Android

In my case, I have discovered that this error will happen if I leave an open transaction left.

In other words: If you forget to commit or rollback a transaction, in the next time you enter in your application, this error raises up.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser275788View Question on Stackoverflow
Solution 1 - AndroidforyouView Answer on Stackoverflow
Solution 2 - AndroiddIvYaNsH sInGhView Answer on Stackoverflow
Solution 3 - AndroidJanuszView Answer on Stackoverflow
Solution 4 - AndroidhrehmanView Answer on Stackoverflow
Solution 5 - AndroidVishal KhakhkharView Answer on Stackoverflow
Solution 6 - AndroidJan BerkelView Answer on Stackoverflow
Solution 7 - AndroidChristianView Answer on Stackoverflow