SQLiteException: 没有这样的表[英] SQLiteException: no such table

本文是小编为大家收集整理的关于SQLiteException: 没有这样的表的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我使用自己的SQLITE3数据库,而不是每次应用程序运行时创建新的数据库,因为我有几张桌子,其中包含我试图显示的静态数据.我创建了数据库,并将其放在资产文件夹中.然后,我创建了数据库助手,当我启动应用程序时,我可以毫无问题地打开数据库,但是当我尝试使用以下代码打开第一表

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,但是当我检查数据库展示器时.

我缺少什么?

推荐答案

您是否将数据库从资产文件夹移至模拟器上的/data/data/YOUR_PACKAGE/databases/?

在如果不存在数据库,则将数据库移至/data/data/YOUR_PACKAGE/databases/.

在这里是另一个简短而简单的解决方案.

其他推荐答案

设置 - >应用程序 - >管理应用程序 - >(单击您的应用程序) - >清除数据

其他推荐答案

每当您在现有数据库中创建新表时,表不创建,因为数据库处理程序的发电函数不会每次调用,而仅在需要时调用(例如未启动数据库).如果不是这种情况,您新创建的表实际未创建.清除数据迫使数据库实例化.

本文地址:https://www.itbaoku.cn/post/102444.html

问题描述

I am using my own SQLite3 database as opposed to creating a new one each time my app runs, as I have a few tables with static data that I am trying to display. I created my database and placed it in my assets folder. I then created my database helper and when I start my app I can open my database without problem but when I try to open my first table using the following code

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


It throws an error saying android.database.sqlite.SQLiteException: no such table: exhibitor: , while compiling: SELECT _id, EXHIBITOR FROM exhibitor ORDER BY EXHIBITOR but when I check the database exhibitor is there.

What am I missing?

推荐答案

Have you moved the database from the assets folder to /data/data/YOUR_PACKAGE/databases/ on the emulator?

This is a good detailed post about moving the database to /data/data/YOUR_PACKAGE/databases/ if it does not exist.

Here is another short and simple solution to it.

其他推荐答案

Settings -> Applications -> Manage Applications -> (Click on your application) -> Clear data

其他推荐答案

Whenever you create new table in an existing database the table doesnt create because the OnCreate function of database handler will not be called everytime but only if required(like database not initiated). If that is not the case your newly created table actually hasnt created. Clear the data to force the db to instantiate itself.