Android 关于sqlite数据库的问题,没有这样的表:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2342346/
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
problem about sqlite database, no such table:
提问by user275788
I open a sqlite database and use rawquery to get data.
我打开一个 sqlite 数据库并使用 rawquery 来获取数据。
But the log.e show the information:
但 log.e 显示信息:
android.database.sqlite.SQLiteException: no such table: types:
android.database.sqlite.SQLiteException:没有这样的表:类型:
But, I really have this table.
但是,我真的有这张桌子。
And i also try to use the other sql ,But also get the error message such as
而且我也尝试使用其他 sql ,但也会收到错误消息,例如
android.database.sqlite.SQLiteException: no such table: malls:
android.database.sqlite.SQLiteException:没有这样的表:商场:
I am sure there are this two tables. So why get the error message?
我确定有这两张表。那么为什么会收到错误消息呢?
采纳答案by CommonsWare
If this is on the emulator, use DDMS File Explorer or adb pull
to download a copy of the database file and confirm its contents.
如果这是在模拟器上,请使用 DDMS 文件资源管理器或adb pull
下载数据库文件的副本并确认其内容。
And i crate a custom SQLiteOpenHelper to copy this file to path : /data/data/com.SGMalls/databases/mallMapv2.sqlite
我创建了一个自定义 SQLiteOpenHelper 将此文件复制到路径:/data/data/com.SGMalls/databases/mallMapv2.sqlite
If you are attempting to copy the file in SQLiteOpenHelper
's onCreate()
, you are too late. I would do it before then.
如果您试图复制SQLiteOpenHelper
's 中的文件onCreate()
,则为时已晚。我会在那之前做。
So the copy file code may be can not copy the complete file.
所以复制文件的代码可能无法复制完整的文件。
It is more likely you would get an error about a corrupt file in that case.
在这种情况下,您更有可能收到有关损坏文件的错误消息。
回答by dev.serghini
If you have multiple contents providers, you might think that your table exists while it does not. In which case the error you are getting is legitimate.
如果您有多个内容提供者,您可能会认为您的表存在而实际上不存在。在这种情况下,您得到的错误是合法的。
Take a look here for details and solution: http://devserghini.blogspot.com/2010/11/android-sqliteopenhelper-and-multiple.html
看看这里的细节和解决方案:http: //devserghini.blogspot.com/2010/11/android-sqliteopenhelper-and-multiple.html
回答by zacharia
I think this error occurs when you change the table structure. To solve this, clean the data (Settings-> Manage application-> Clear data) before installing the new application.
我认为当您更改表结构时会发生此错误。要解决此问题,请在安装新应用程序之前清除数据(设置->管理应用程序->清除数据)。
Regards.
问候。
回答by 3DRaven
SQLiteDatabase.execSQL()
interpretation takes a single string sql, ending with ";". Two lines have not interpreted.
SQLiteDatabase.execSQL()
解释采用单个字符串 sql,以“;”结尾。两行没有解释。
Creating tables in a few lines sql just not executed.
在几行中创建表 sql 只是没有执行。