У меня есть только один конструктор, но я не знаю, почему компилятор продолжает говорить «Есть несколько хороших конструкторов, и Room выберет конструктор без аргументов».
Я использую java и Kotlin одновременно с переходом на Kotlin, но не очень хорошо с ним знаком.
Встроенный класс BluetoothInfo находится в Kotlin, а класс MarkerEntity в java.
MarkerEntity. java
@Entity(tableName = "marker_table", indices = {@Index(value = "light_id", unique = true)})
public class MarkerEntity {
@PrimaryKey(autoGenerate = true)
private int id;
@ColumnInfo(name = "light_id")
private int lightId;
@ColumnInfo(name = "lat")
private int x;
@ColumnInfo(name = "lng")
private int y;
@ColumnInfo(name = "title")
private String title = "Default LightMarker";
@ColumnInfo(name = "description")
private String description = "No Description";
@Embedded
private BluetoothInfo bluetoothInfo;
public MarkerEntity(int lightId, int x, int y, String title, String description, BluetoothInfo bluetoothInfo) {
this.lightId = lightId;
this.x = x;
this.y = y;
if (title != null) this.title = title;
if (description != null) this.description = description;
if (bluetoothInfo != null) {
this.bluetoothInfo = bluetoothInfo;
} else {
bluetoothInfo = new BluetoothInfo();
}
}
public int getId() {
return id;
}
public int getLightId() {
return lightId;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public BluetoothInfo getBluetoothInfo() {
return bluetoothInfo;
}
public void setLightId(int light_id) {
this.lightId = light_id;
}
public void setId(int id) {
this.id = id;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setBluetoothInfo(BluetoothInfo bluetoothInfo) {
this.bluetoothInfo = bluetoothInfo;
}
@Override
public String toString() {
return lightId + " " + x + " " + y + " " + title + " " + description + "\n" + bluetoothInfo.toString();
}
}
BluetoothInfo.kt
data class BluetoothInfo
@JvmOverloads constructor(private val bluetoothName: String = INVALID_BT_STRING, private val bluetoothAddress: String = INVALID_BT_STRING,
private val bluetoothUuid: String = INVALID_BT_STRING, private val bluetoothMajor: String = INVALID_BT_STRING,
private val bluetoothMinor: String = INVALID_BT_STRING, private val rssi: Int = INVALID_RSSI,
private val distance: Float = INVALID_DIST) {
companion object {
const val INVALID_RSSI = 99
const val INVALID_DIST = -1f
const val INVALID_BT_STRING = "invalid"
}
override fun toString(): String {
return "name: $bluetoothName, addr: $bluetoothAddress, uuid: $bluetoothUuid \n" +
"major: $bluetoothMajor, minorL $bluetoothMinor, rssi: $rssi" +
"dist: $distance"
}
}
РЕДАКТИРОВАТЬ:
Я пробовал Android Studio Kotlin конвертер для MarkerEntity. java, но ошибка все еще сохраняется.
MarkerEntity.kt
@Entity(tableName = "marker_table", indices = [Index(value = ["light_id"], unique = true)])
class MarkerEntity(lightId: Int, x: Int, y: Int, title: String?, description: String?, bluetoothInfo: BluetoothInfo?) {
@PrimaryKey(autoGenerate = true)
var id = 0
@ColumnInfo(name = "light_id")
var lightId: Int
@ColumnInfo(name = "lat")
var x: Int
@ColumnInfo(name = "lng")
var y: Int
@ColumnInfo(name = "title")
var title = "Default LightMarker"
@ColumnInfo(name = "description")
var description = "No Description"
@Embedded
var bluetoothInfo: BluetoothInfo? = null
override fun toString(): String {
return lightId.toString() + " " + x + " " + y + " " + title + " " + description + "\n" + bluetoothInfo.toString()
}
init {
var bluetoothInfo = bluetoothInfo
this.lightId = lightId
this.x = x
this.y = y
if (title != null) this.title = title
if (description != null) this.description = description
if (bluetoothInfo != null) {
this.bluetoothInfo = bluetoothInfo
} else {
bluetoothInfo = BluetoothInfo()
}
}
}