Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 可以在房间数据库的构造函数中使用@Ignore字段吗?_Java_Android_Android Room_Pojo_Android Database - Fatal编程技术网

Java 可以在房间数据库的构造函数中使用@Ignore字段吗?

Java 可以在房间数据库的构造函数中使用@Ignore字段吗?,java,android,android-room,pojo,android-database,Java,Android,Android Room,Pojo,Android Database,我有一个房间数据库。在我的实体(PerformanceEntry)中,我不想在表中保存一个字段(String studentName),但我想访问列表中的字段 我对字段使用了@Ignore,但在这种情况下,我也不能在构造函数中使用字段 我想知道有什么解决办法吗?或者我必须在表中创建字段 注: 此字段是临时值,我不想将其保存到表中 @Entity(tableName = "performance") public class PerformanceEntry { @ColumnInfo(name

我有一个
房间数据库
。在我的
实体
(PerformanceEntry)中,我不想在表中保存一个字段(String studentName),但我想访问列表中的字段

我对字段使用了
@Ignore
,但在这种情况下,我也不能在构造函数中使用字段

我想知道有什么解决办法吗?或者我必须在表中创建字段

注: 此字段是临时值,我不想将其保存到表中

@Entity(tableName = "performance")
public class PerformanceEntry {

@ColumnInfo(name = "entry_id")
    @PrimaryKey(autoGenerate = true)
    private int entryId;
    @ColumnInfo(name = "class_id")
    private int classId;
    @ColumnInfo(name = "student_id")
    private String studentId;
    @ColumnInfo(name = "class_date")
    private String classDate;
    private boolean absent;
    private boolean delay;
    private int positive;
    private int negative;

    @Ignore
    private String studentName;

    public PerformanceEntry(int entryId, int classId, String studentId, String classDate, boolean absent, boolean delay, int positive, int negative, String studentName) {
    this.entryId = entryId;
    this.classId = classId;
    this.studentId = studentId;
    this.classDate = classDate;
    this.absent = absent;
    this.delay = delay;
    this.positive = positive;
    this.negative = negative;
    this.studentName = studentName;
    }
}
错误:

error: Cannot find setter for field.

你可以使用annotation@Transient而不是@Ignore

你可以使用annotation@Transient而不是@Ignore

试着把
@PrimaryKey
字段放在你的
@Ignore
字段下面。

不,我想这不是我的答案。不,这不是我的答案回答我想。你能提供完整的错误日志吗?您共享的代码不需要任何设置程序来设置
studentName
您是否尝试过两个带和不带“studentName”的构造函数?是的,我尝试过,但不起作用,上面显示了错误您可以提供完整的错误日志吗?您共享的代码不需要任何setter来设置
studentName
您是否尝试了两个带和不带“studentName”的构造函数?是的,我尝试了,但不起作用,并显示了上述错误