我正在使用我自己的 SQLite3 数据库,而不是每次我的应用程序运行时都创建一个新数据库,因为我有几个包含静态数据的表要显示。我创建了我的数据库并将它放在我的 Assets 文件夹中。然后,我创建了数据库帮助器,当我启动应用程序时,可以毫无问题地打开数据库,但是当我尝试使用以下代码打开第一个表时

private Cursor getData()
{
    try
    {
        myDbHelper = new DatabaseHelper(this);
        SQLiteDatabase db = myDbHelper.getReadableDatabase();
        Cursor cursor = db.query("exhibitor", FROM, null, null, null,null, ORDER_BY);
        startManagingCursor(cursor);
        return cursor;
    }
    catch(SQLiteException e)
    {
        String err = e.toString();
        return null;
    }
}

它抛出一个错误,说 android.database.sqlite.SQLiteException: no such table: exhibitor: , while compiling: SELECT _id, EXHIBITOR FROM exhibitor ORDER BY EXHIBITOR 但是当我检查数据库展示者在那里时。
我错过了什么?

最佳答案

您是否将数据库从 Assets 文件夹移动到模拟器上的 /data/data/YOUR_PACKAGE/databases/

This is a good detailed post 关于将数据库移动到 /data/data/YOUR_PACKAGE/databases/ 如果它不存在。

Here 是另一个简短的解决方案。

关于android - SQLiteException : no such table,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4991368/

10-12 13:12