我有一个示例Android应用,我在其中创建了一个数据库,创建了一个表,然后将数据插入到表中。第二天,在打开Eclipse IDE并通过模拟器运行我的应用程序时,应用程序突然关闭,并显示No such table
的SQLLiteException。
我的MainActivity代码如下:
SQLiteDatabase DB = Context.openOrCreateDatabase(
"WaterElectricityReadingDataBase.db",
MODE_WORLD_READABLE, null);
final String CREATE_TABLE = "create table if not exists "
+ TABLE_NAME + "(" + COLUMN_NAME_READING_ID
+ " integer primary key autoincrement,"
+ COLUMN_NAME_READING_MODE + " text not null,"
+ COLUMN_NAME_PASTDATETIME + " date not null, "
+ "EndDateTime date not null, "
+ COLUMN_NAME_READINGVALUE + " integer not null" + ");";
DB.execSQL(CREATE_TABLE);
表或数据不是持久的吗?我在设置中遗漏了什么吗?
请纠正我,谢谢。
答案 0 :(得分:0)
更改您的代码,如:
final String CREATE_TABLE = "create table if not exists "
+ TABLE_NAME + "(" + COLUMN_NAME_READING_ID
+ " integer primary key autoincrement,"
+ COLUMN_NAME_READING_MODE + " text not null,"
+ COLUMN_NAME_PASTDATETIME + " date not null, "
+ "EndDateTime date not null, "
+ COLUMN_NAME_READINGVALUE + " integer not null);";
告诉我工作与否?
祝你好运。