Я пытаюсь настроить Room в моем приложении для Android.Я получаю эту ошибку, но я действительно не понимаю, почему.
Полная ошибка: у сущностей и 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 */
}
Photo Entity
@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 */
}
Network Entity
@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;
}
@PrimaryKey(autoGenerate = true)
private int id;
private String ssid;
private String bssid;
private String capabilities;
private long timestamp;
@ColumnInfo(name = "marker_id")
private int markerId;
/* Getters and setters */
}
А вот мои зависимости дляНомер в моем файле build.gradle:
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
Я посмотрел на многие подобные вопросы, и ни один из них не решил мою проблему.