数据库光标和列的错误

时间:2016-07-10 13:25:30

标签: android database cursor

这是我数据库的一部分。我按照列的位置进行操作,但仍然存在错误。

public static final String CREATE_TABLE_NOTE = "create table " + NOTE_TABLE + " ( "
        + COLUMN_ID + " integer primary key autoincrement, "
        + COLUMN_TITLE + " text not null, "
        + COLUMN_MESSAGE + " text not null, "
        + COLUMN_THOUGHTS + " text not null, "
        + COLUMN_CATEGORY + " text not null, "
        + COLUMN_DATE + ");";


private Note cursorToNote(Cursor cursor){

//this part is underlined in red(error)

Note newNote = new Note (cursor.getString(1), cursor.getString(2),cursor.getString(3),
                        Note.Category.valueOf(cursor.getString(4)), cursor.getLong(0), cursor.getLong(5));
                return newNote;
            }

Note.java

public Note (String title, String message, Category category, long noteId, long dateCreatedMilli){
        this.title = title;
        this.message = message;
        this.thoughts = thoughts;
        this.category = category;
        this.noteId = noteId;
        this.dateCreatedMilli = dateCreatedMilli;
    }

2 个答案:

答案 0 :(得分:2)

您在构造函数输入参数中缺少thoughts。将其更改为:

public Note (String title, String message, String thoughts, Category category, long noteId, long dateCreatedMilli){
        this.title = title;
        this.message = message;
        this.thoughts = thoughts;
        this.category = category;
        this.noteId = noteId;
        this.dateCreatedMilli = dateCreatedMilli;
    }

答案 1 :(得分:1)

Note()构造函数的第三个参数是Category的类型,但您传递了String(由cursor.getString(3)方法返回)