为android应用程序插入数据库时出现问题
当我尝试插入数据库时,我不断遇到以下错误:为android应用程序插入数据库时出现问题,android,database,sqlite,compiler-errors,insertion,Android,Database,Sqlite,Compiler Errors,Insertion,当我尝试插入数据库时,我不断遇到以下错误: 08-14 11:50:21.455: E/SQLiteLog(27688): (1) table exercises has no column named reps 08-14 11:50:21.495: E/SQLiteDatabase(27688): Error inserting reps=4 title= BarBell Curls weight=4 notes=db date=August-14-2013 08-14 11:50:21.
08-14 11:50:21.455: E/SQLiteLog(27688): (1) table exercises has no column named reps
08-14 11:50:21.495: E/SQLiteDatabase(27688): Error inserting reps=4 title= BarBell Curls weight=4 notes=db date=August-14-2013
08-14 11:50:21.495: E/SQLiteDatabase(27688): android.database.sqlite.SQLiteException: table exercises has no column named reps (code 1): , while compiling: INSERT INTO exercises(reps,title,weight,notes,date) VALUES (?,?,?,?,?)
以下是我对创建语句的理解:
//数据库创建sql语句
private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " (" + KEY_ROWID + " integer primary key autoincrement, "
+ KEY_TITLE + " text not null, "
+ DATE_SELECTED + " text not null, "
+ WEIGHT_INPUT + " text not null, "
+ REPS_INPUT + " text not null, "
+ KEY_BODY + " text not null" + ");";
//方法插入行
public long createExercise(String title, String date, String weight, String reps, String body)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(DATE_SELECTED, date);
initialValues.put(WEIGHT_INPUT, weight);
initialValues.put(REPS_INPUT, reps);
initialValues.put(KEY_BODY, body);
return myDatabase.insert(DATABASE_TABLE, null, initialValues);
}
我知道我只是错过了一些简单的东西,任何帮助都将不胜感激!
CheersSQLite错误指出,表格练习没有名为reps的列。您以前是否创建过此数据库,后来又添加了reps\u输入?如果是,则数据库仍然存在,前提是您尚未卸载应用程序或从保存应用程序的位置删除数据库。尝试从零开始,删除应用程序并重新安装。若数据库存储在外部存储器上,则删除数据库您是否使用SQLiteOpenHelper?如果是这样,您是否在最初创建表之后将reps列添加到create字符串中?我没有正确打开数据库。我将我的open添加到构造函数中,不再出现任何错误。我还没有让它正确显示,但这是另一个问题。谢谢你的建议。是的,我认为这很明显,但你的答案并没有回答为什么会发生这种情况。可能是表格创建时出现了拼写错误。只是想给他指出正确的方向。我没有打开这里:public calendardAdapterContext ctx{this.mCtx=ctx;open;}