我正在尝试在我的 Android 应用程序中设置 Room。我收到此错误,但我真的不明白为什么。
完全错误:实体和 Pojos 必须有一个可用的公共构造函数。您可以有一个空的构造函数或参数与字段匹配的构造函数(按名称和类型)。
我正在使用 1.1.1 版的 Room。我尝试了空构造函数、带参数的构造函数,还修复了我遇到的所有警告,这样就没有其他问题了。
这是我的实体:
标记实体
@Entity(tableName = "markers")
public class Marker {
public Marker(@Nullable String title, @Nullable String snippet, String latitude, String longitude, float color) {
this.title = title;
this.snippet = snippet;
this.latitude = latitude;
this.longitude = longitude;
this.color = color;
}
@PrimaryKey(autoGenerate = true)
private int id;
private String title;
private String snippet;
private String latitude;
private String longitude;
private float color;
/* Getters and setters */
}
照片实体
@Entity(tableName = "photos",
foreignKeys = @ForeignKey(entity = Marker.class,
parentColumns = "id",
childColumns = "marker_id"),
indices = {@Index("marker_id")})
public class Photo {
public Photo(String imageBase64, int markerId) {
this.imageBase64 = imageBase64;
this.markerId = markerId;
}
@PrimaryKey(autoGenerate = true)
private int id;
@ColumnInfo(name = "image")
private String imageBase64;
@ColumnInfo(name = "marker_id")
private int markerId;
/* Getters and setters */
}
网络实体
@Entity(tableName = "networks",
foreignKeys = @ForeignKey(entity = Marker.class,
parentColumns = "id",
childColumns = "marker_id"),
indices = {@Index("marker_id")})
public class Network {
public Network(String ssid, String bssid, String capabilities, long timestamp, int markerId) {
this.ssid = ssid;
this.bssid = bssid;
this.capabilities = capabilities;
this.timestamp = timestamp;
this.markerId = markerId;
}
}
我看了很多这样的问题,但没有一个能解决我的问题。
大话西游666
Smart猫小萌
达令说
随时随地看视频慕课网APP
相关分类