0

我正在尝试在 Android 的 SQLite 数据库中创建一个表。我设置了所有内容,但它一直告诉我我没有“年龄”列,而我显然这样做了!任何人都可以帮忙吗?

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "contactsManager";

// Contacts table name
private static final String TABLE_CONTACTS = "contacts";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PH_NO = "phone_number";
private static final String KEY_AGE = "age";

public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
            + KEY_PH_NO + " TEXT," + KEY_AGE + "TEXT" + ")";
    db.execSQL(CREATE_CONTACTS_TABLE);
}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS titles");
    onCreate(db);
}
4

2 回答 2

6

String在声明列的位置放置一个空格age

...+ KEY_PH_NO + " TEXT," + KEY_AGE + " TEXT" + ")";

此外,执行此操作后,您需要卸载该应用程序,然后重新安装它以进行此修改(因此onCreate将再次调用该方法)。

于 2012-05-17T21:30:27.293 回答
0

您需要TEXT在下面的代码中添加一个空格字符:

KEY_AGE + "TEXT" 
于 2012-05-17T21:30:46.577 回答