我的数据库中存在数据问题。 我试着把一些数据放在我的微调器上。但我有空的旋转器。 我真的不明白我错在哪里。 这是我的代码
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE "+TABLE_NAME+" ("+colCountryID+ " INTEGER PRIMARY KEY , "+
colCountryName+ " TEXT)");
InsertCountry(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
onCreate(db);
}
public Cursor getAllDepts() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cur = db.rawQuery("SELECT " + colCountryID + " as _id, " + colCountryName + " from " + TABLE_NAME, new String[] {});
return cur;
}
public void InsertCountry(SQLiteDatabase db) {
ContentValues cv = new ContentValues();
cv.put(colCountryID, 1);
cv.put(colCountryName, "GB");
db.insert(TABLE_NAME, null, cv);
Log.w(TABLE_NAME, "insert");
}
和
database = new DBTestHelper(this);
Cursor c=database.getAllDepts();
startManagingCursor(c);
SimpleCursorAdapter ca=new SimpleCursorAdapter(this,R.layout.dvdfg, c, new String [] {DBTestHelper.colCountryName,"_id"}, new int []{R.id.text});
//ca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
counry.setAdapter(ca);
答案 0 :(得分:0)
Cursor cur = db.rawQuery("SELECT " + colCountryID + " as _id, " + colCountryName + " from " + TABLE_NAME, new String[] {});
我觉得很奇怪尝试传递一个空数组作为最后一个参数
Cursor cur = db.rawQuery("SELECT " + colCountryID + " as _id, " + colCountryName + " from " + TABLE_NAME, null);