【发布时间】:2015-05-19 14:39:49
【问题描述】:
我正在尝试通过 android 执行 SQL 查询 - 我目前无法这样做。我收到一个致命错误,并且在尝试执行我已验证有效的简单查询时应用程序关闭:SELECT * FROM TblMovie WHERE MovieYear = 1975
但是 - 当我尝试在我的应用中这样做时:
主活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbhelper = new DBHelper(this);
List<String> list = dbhelper.getData();
TextView textView1 = (TextView) findViewById(R.id.textView1);
TextView textView2 = (TextView) findViewById(R.id.textView2);
textView1.setText(list.get(0));
textView2.setText(list.get(1));
...
DBHelper:
public List<String> getData() {
db = this.getReadableDatabase();
List<String> data = new ArrayList<String>();
Cursor c = db.rawQuery("SELECT * FROM TblMovie WHERE MovieYear = 1975", null);
while (c.moveToNext()) {
data.add(c.getString(0));
data.add(c.getString(1));
}
c.close();
db.close();
return data;
}
Logcat:
05-19 10:24:59.983: E/AndroidRuntime(24736): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: android.database.sqlite.SQLiteException: no such table: TblMovie (code 1): , while compiling: SELECT * FROM TblMovie WHERE MovieYear = 1975
http://pastebin.com/0mAD87jJ
另外 - 我发现这篇文章作为参考:
No such table: (code 1) while compiling: SELECT * FROM event
我尝试在我的平板电脑而不是模拟器上运行它 - 仍然无法正常工作。我也尝试清除数据 - 这也不起作用。我的资产文件夹中有数据库,所以我不确定它为什么不起作用。
编辑:
为什么投反对票?我很确定这是一个有效且不是非常书面/记录/研究的问题。
数据库截图:
【问题讨论】:
-
我会建议卸载并重新安装该应用程序。
-
是的,这是一个很好的建议@AAnkit,如果它不起作用,请发布您的 CREATE TABLE 查询。
-
显示 CREATE TABLE 代码。该指令似乎有错误。
-
我卸载并重新安装 - 仍然崩溃。我在资产文件夹中使用预先创建的数据库 - 我不使用 CREATE TABLE 代码:)
标签: android sqlite android-sqlite fatal-error forceclose