It says that the column name bmi does not exist. The resulting Error message is that the system cannot find a column called bmi. I checked it already a couple of times and I couldn't find a mistake in the code. Maybe you guys see one... The full Stack Dump is attached after the code.
public class MyDBHandler extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "bmiwerte.db";
public static final String TABLE_BMIS = "bmis";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_BMI = "bmi";
public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
private static final String CREATE_TABLE_BMIS = "CREATE TABLE "
+TABLE_BMIS
+" ("
+COLUMN_ID
+" INTEGER AUTOINCREMENT, "
+COLUMN_NAME
+" TEXT PRIMARY KEY"
+COLUMN_BMI
+" TEXT"
+");";
@Override
public void onCreate(SQLiteDatabase db) {
//Lässt Query in SQL laufen
Log.i("exxxx", "Creating Check");
db.execSQL(CREATE_TABLE_BMIS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST " + TABLE_BMIS);
onCreate(db);
}
public void addValues(BMI_Werte wert){
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, wert.get_name());
values.put(COLUMN_BMI, wert.get_bmiWert().toString());
Log.i("exxx", wert.get_name());
Log.i("exxxx", wert.get_bmiWert().toString());
SQLiteDatabase db = getWritableDatabase();
db.insert(TABLE_BMIS, null, values);
db.close();
}
public void deleteValues(String name){
Log.i("exxxx", "deleteValuse");
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_BMIS + " WHERE " +
COLUMN_NAME + "=\"" + name + "\";");
}
public String databaseToString(){
String dbString = "";
SQLiteDatabase db = this.getWritableDatabase();
String query = "SELECT * FROM " + TABLE_BMIS;
String test = "DESCRIBE " + TABLE_BMIS;
Cursor c = db.rawQuery(query, null);
c.moveToFirst();
while(!c.isAfterLast()){
if(c.getString(c.getColumnIndex("name")) != null){
dbString += c.getString(c.getColumnIndex("name"));
dbString += "\n";
}
c.moveToNext();
}
db.close();
return dbString;
}
}
Error and Stack Dump:
Aucun commentaire:
Enregistrer un commentaire