我正在为一个应用程序创建数据库,这是我的代码给我错误没有这样的表找到问题请帮忙
protected static final String player = ("CREATE TABLE " + table_player
+ " (" + player_id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ player_name + " TEXT, " + player_dob + "INTEGER" + player_gender + " TEXT);");
oncreatdatabase() 中的
插入方法: db.execSQL(player);
public long insert_Place( )//, String _Placealti)
{
try
{
SQLiteDatabase db= this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(player_name, "name");
contentValues.put(player_dob, "123");
contentValues.put(player_gender, "male");
return db.insert(table_player, null, contentValues);
}
catch(Exception ex)
{
Log.d("Insert: insert_Place",ex.toString());
}
return 0;
}
答案 0 :(得分:2)
在,
之后错过INTEGER
并在列名和列类型之间添加一个空格
+ " INTEGER " + player_gender + " + " TEXT);")// Missed , after INTEGER and add one space before INTEGER
protected static final String player = ("CREATE TABLE " + table_player
+ " (" + player_id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ player_name + " TEXT, " + player_dob + " INTEGER," + player_gender + " TEXT);");
这就是为什么你的桌子没有装箱而且你没有这样的桌子找到了例外
答案 1 :(得分:1)
由于语法错误,未创建表:
player_name + " TEXT, " + player_dob + "INTEGER" + player_gender + " TEXT);"
应该是
player_name + " TEXT, " + player_dob + " INTEGER, " + player_gender + " TEXT);"
答案 2 :(得分:1)
//write to this
String player = "CREATE TABLE IF NOT EXISTS "
+ table_player + "(" + player_id
+ " integer primary key , " + player_name
+ " text ,"+ player_dob+" integer,"+player_gender+" text);";