1
裏面我Input.java文件我有SQLite的 - 如何解決語法錯誤(代碼1)
public class Input {
private int _id;
private String _username;
public Input(){
}
public Input(String username){
this._username = username;
}
public void set_id(int _id) {
this._id = _id;
}
public void set_username(String _username) {
this._username = _username;
}
public int get_id() {
return _id;
}
public String get_username() {
return _username;
}
}
和我DBHandler.java內
public class DBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "input.db";
public static final String TABLE_INPUT = "input";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_USERNAME = "username";
public DBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_INPUT + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT " +
COLUMN_USERNAME + " TEXT " +
");";
db.execSQL(query);
}
每當我試着執行此,我得到錯誤:
Caused by: android.database.sqlite.SQLiteException: near "username": syntax error (code 1): , while compiling: CREATE TABLE input(_id INTEGER PRIMARY KEY AUTOINCREMENT username TEXT);
我究竟在做什麼錯?
現在好了,我覺得很傻這個固定謝謝! –
不客氣,你可以把它標記出來,這樣在未來可以幫助別人 – Psypher
需要等5分鐘才能接受。 –