Android SQLite 异常:没有这样的表错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/934237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLite Exception: no such table Error
提问by MySQL DBA
Possible Duplicate:
Android Sqlite - “No Such Table” Error
We are trying to develop an application on Android. We are using SQLite database and on phone we are getting
我们正在尝试在 Android 上开发应用程序。我们正在使用 SQLite 数据库,在电话上我们得到了
SQLiteException:no such table.
SQLiteException:没有这样的表。
It is working fine on simulator.
它在模拟器上运行良好。
Can anyone provide any input on this?
任何人都可以提供任何意见吗?
采纳答案by Jay
If you don't specify the database file name correctly I believe it falls back to creating an empty database. This is generally the cause of 'table not found'. Check your path and database file name.
如果您没有正确指定数据库文件名,我相信它会回退到创建一个空数据库。这通常是“找不到表”的原因。检查您的路径和数据库文件名。
回答by png
I had faced a different flavour of the same problem.
我遇到了同一个问题的不同风味。
I was getting no such table
error when I try to insert.
我no such table
尝试插入时出错。
Before inserting, the code was calling
在插入之前,代码正在调用
mDb = mDbHelper.getWritableDatabase();
getWritableDatabase()
, when called first time will call onCreate()
getWritableDatabase()
, 当第一次被调用时会调用 onCreate()
I had my SQL query to create the table within this oncreate method
我有我的 SQL 查询来在这个 oncreate 方法中创建表
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
Log.v("INFO1","creating db");
//Toast.makeText(mCtx, "created", Toast.LENGTH_SHORT).show();
}
So for me what had happened was, the db
was successfully created when the application was first run but no table due to some other errors.
Later whenever the application is run, onCreate()
is never called as db
is already there and thus no table created, so all further SQL commands failed.
所以对我来说发生的事情是,db
当应用程序第一次运行时成功创建,但由于其他一些错误而没有表。以后每当应用程序运行时,onCreate()
都不会像db
已经存在的那样调用,因此没有创建表,因此所有进一步的 SQL 命令都失败了。
So I moved creating table out of onCreate()
, and now its working
所以我把创建表移出了onCreate()
,现在它的工作
回答by Abhinav Manchanda
Some people have been able to solve the problem using the steps mentioned here. It seems to me that this problem exists on certain versions of Android 2.2. I have incorporated this change in my code, though I'm still looking for Beta testers with to see if it actually works.
有些人已经能够使用这里提到的步骤解决问题。在我看来,这个问题存在于某些版本的 Android 2.2 上。我已经在我的代码中加入了这个更改,但我仍在寻找 Beta 测试人员,看看它是否真的有效。