我正在编写一个安卓应用程序。
这是我的 BDHelper 课程:
public class BD_Helper extends SQLiteOpenHelper{
private static final String BD_NOMBRE = "BD_PAED.db";
private static final int BD_VERSION = 1;
private static final String TABLA_AUDIT_NOMBRE = "audit";
private static final String TABLA_CONTROLES_NOMBRE = "controles";
private static final String crearAudit =
"CREATE TABLE " + TABLA_AUDIT_NOMBRE + " (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"usuario TEXT, " +
"clave TEXT, " +
"userid INTEGER, " +
"pin TEXT, " +
"tema TEXT, " +
"colorFondo TEXT, " +
"color TEXT, " +
"colorFuente TEXT)";
private static final String crearControles =
"CREATE TABLE " + TABLA_CONTROLES_NOMBRE + " (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"entryTypeId TEXT, " +
"statusTypeId TEXT, " +
"momentTypeId TEXT, " +
"activityTypeId TEXT, " +
"activityDuration TEXT, " +
"activityTypeOthers TEXT, " +
"intensityTypeId TEXT, " +
"measurementTime TEXT, " +
"glucosePre TEXT, " +
"CHRations TEXT, " +
"rapidInsulin TEXT, " +
"slowInsulin TEXT, " +
"glucosePost TEXT);";
public BD_Helper(Context context){
super(context, BD_NOMBRE, null, BD_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(crearAudit);
db.execSQL(crearControles);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists "+ TABLA_AUDIT_NOMBRE);
db.execSQL("drop table if exists "+ TABLA_CONTROLES_NOMBRE);
onCreate(db);
}
}
在其他类中,我正在尝试使用简单的光标适配器来显示控件数据库的信息:
private void cargaDatos(){
String[] from;
cursor = bdHelper.obtenerControles(entryTypeId);
startManagingCursor(cursor);
from = new String[] {BD_ControlesAdapter.CAMPO_MEASUREMENTTIME,BD_ControlesAdapter.CAMPO_ACTIVITYTYPEID};
int[] to = new int[]{R.id.fila_fecha,R.id.fila_tipo};
SimpleCursorAdapter controles = new SimpleCursorAdapter(this,R.layout.fila_controles,cursor,from,to,0);
setListAdapter(controles);
}
但这不起作用,new SimpleCursorAdapter
抛出一个:
IllegalArgumentException: column '_id' does not exist.
如果我检查我的 sqlite 数据库,则此列是在此数据库中完美创建的。
任何想法?