相关疑难解决方法(0)

Android room persistent library - 如何插入具有List对象字段的类

Android房间持久化库中如何将整个Model对象插入到本身具有另一个列表的表中.

让我告诉你我的意思:

@Entity(tableName = TABLE_NAME)
public class CountryModel {

    public static final String TABLE_NAME = "Countries";

    @PrimaryKey
    private int idCountry;

    private List<CountryLang> countryLang = null;

    public int getIdCountry() {
        return idCountry;
    }

    public void setIdCountry(int idCountry) {
        this.idCountry = idCountry;
    }

    public String getIsoCode() {
        return isoCode;
    }

    public void setIsoCode(String isoCode) {
        this.isoCode = isoCode;
    }

    /** 
        here i am providing a list of coutry information how to insert 
        this into db along with CountryModel at same …
Run Code Online (Sandbox Code Playgroud)

android android-room

28
推荐指数
5
解决办法
4万
查看次数

房间持久性:实体和POJO必须具有可用的构造函数

我试图通过Room Persistence库将数据库添加到我的Android应用程序中.我正确地遵循了说明,但在编译时得到了上述错误.另外Room无法找到我的getter,虽然我可以在我的代码中清楚地看到所有这些.任何帮助将非常感激.提前致谢.

这是我的实体代码:

@Entity(tableName = "users", indices = @Index(value = "username", unique = true))
public class User {

@NonNull
public String getuId() {
    return uId;
}

public void setuId(@NonNull String uId) {
    this.uId = uId;
}

public String getuUsername() {
    return uUsername;
}

public void setuUsername(String uUsername) {
    this.uUsername = uUsername;
}

@NonNull
public String getuPassword() {
    return uPassword;
}

public void setuPassword(@NonNull String uPassword) {
    this.uPassword = uPassword;
}

public String getuEmail() {
    return uEmail;
}

public void setuEmail(String …
Run Code Online (Sandbox Code Playgroud)

java android android-room

11
推荐指数
1
解决办法
6425
查看次数

如何忽略带有 Room 的实体字段

我有一个数据类,我Entity从它为我的数据库创建了一个。

这是我的数据类:

@Entity
@Parcelize
data class Tapligh(

    @PrimaryKey(autoGenerate = true)
    var id: Long,

    @SerializedName("title") var title: String?,
    @SerializedName("type") var type: Int?,
    @SerializedName("os") var os: Int?,
    @SerializedName("logo") var logo: String?,
    @SerializedName("template") var template: String?,
    @SerializedName("action") var action: String?,
    @SerializedName("date") var date: String?,
    @Embedded
    @SerializedName("videos") var videos: Videos?,

) : Parcelable {

    fun getTaplighType(): Int {

        return when (this.type) {

            0 -> TaplighType.IMAGE.type
            1 -> TaplighType.VIDEO.type
            else -> TaplighType.NATIVE.type
        }
    }
}

@Parcelize
data class Videos(

    @SerializedName("land") var land: String?, …
Run Code Online (Sandbox Code Playgroud)

android kotlin data-class android-room

7
推荐指数
2
解决办法
2529
查看次数

标签 统计

android ×3

android-room ×3

data-class ×1

java ×1

kotlin ×1