这是我正在使用的课程

public class DBHelper extends SQLiteOpenHelper {

    private static final String DB_FILE = "Database.db";
    private static final String TABLE = "Estudiantes";
    private static final String FIELD_ID = "id";
    private static final String FIELD_NAME = "nombre";
    private static final String FIELD_GRADE = "calificacion";

    public DBHelper(Context context){
        super(context, DB_FILE, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String query = "CREATE TABLE " + TABLE + "(" +
                FIELD_ID + " INTEGER PRIMARY KEY, " +
                FIELD_NAME + " TEXT, " +
                FIELD_GRADE + " INTEGER);";
        db.execSQL(query);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String query = "DROP TABLE IF EXISTS ?";
        String[] params = {TABLE};
        db.execSQL(query, params);
    }

    public void save(String nombre, int calificacion){
        SQLiteDatabase db = getWritableDatabase();
        ContentValues valores = new ContentValues();

        valores.put(FIELD_NAME, nombre);
        valores.put(FIELD_GRADE, calificacion);

        db.insert(TABLE, null, valores);
    }

    public int delete(String nombre){
        SQLiteDatabase db = getWritableDatabase();
        String clause = FIELD_NAME + " = ?";
        String[] args = {nombre};
        return db.delete(TABLE, clause, args);
    }

    public int find(String nombre){
        SQLiteDatabase db = getReadableDatabase();
        String filtrito = FIELD_NAME + " = ?";
        String[] args = {nombre};

        Cursor c = db.query(TABLE, null, filtrito, args, null, null, null);
        int result = -1;

        if(c.moveToFirst()) {
            result = c.getInt(2);
        }

        return result;
    }
}



这是我收到的错误消息:

E/SQLiteLog: (1) table Estudiantes has no column named calificacion
E/SQLiteDatabase: Error inserting calificacion=80 nombre=Fer
android.database.sqlite.SQLiteException:
table Estudiantes has no column named calificacion (code 1): , while compiling:
INSERT INTO Estudiantes(calificacion,nombre) VALUES (?,?)

最佳答案

看起来您稍后在数据库中添加了calificacion列。
我将执行以下操作之一:


卸载并重新安装您的应用程序。
最好的方法是使用drop方法中的recreateonUpdate Estudiantes表,并在更改架构时增加数据库版本。

关于java - E/SQLiteLog:(1)表Estudiantes在android中没有名为calificacion的列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60422419/

10-12 00:36