Android Room错误:即使查询返回的列被注释为非null或原始类型,也没有字段

时间:2019-03-18 05:56:58

标签: java android android-room

所以我想使用Android Studio中的Room加入我的桌子,这是我的模型课。

Ibadah.java

@Entity(tableName = "tibadah")
public class Ibadah implements Serializable {

    @PrimaryKey(autoGenerate = true)
    public int idIbadah;

    @ColumnInfo(name = "nama_ibadah")
    public String namaIbadah;

    @ColumnInfo(name = "deskripsi_ibadah")
    public String deskripsiIbadah;

    @ColumnInfo(name = "satuan_ibadah")
    public String satuanIbadah;

    public String getSatuanIbadah() {
        return satuanIbadah;
    }

    public void setSatuanIbadah(String satuanIbadah) {
        this.satuanIbadah = satuanIbadah;
    }

    public String getDeskripsiIbadah() {
        return deskripsiIbadah;
    }

    public void setDeskripsiIbadah(String deskripsiIbadah) {
        this.deskripsiIbadah = deskripsiIbadah;
    }

    public int getIdIbadah() {
        return idIbadah;
    }

    public void setIdIbadah(int idIbadah) {
        this.idIbadah = idIbadah;
    }

    public String getNamaIbadah() {
        return namaIbadah;
    }

    public void setNamaIbadah(String namaIbadah) {
        this.namaIbadah = namaIbadah;
    }

}

SimpanTarget.java

@Entity(tableName = "tabjoin")

public class SimpanTarget implements Serializable {

    @PrimaryKey(autoGenerate = true)
    public int idSimpan;

    @ColumnInfo(name = "id_ibajoin")
    public int idIbadahJoin;

    @ColumnInfo(name = "id_periode")
    public int idPeriode;

    @ColumnInfo(name = "id_target")
    public int idTarget;

    @ColumnInfo(name = "id_catat")
    public int idCatat;

    @ColumnInfo(name = "id_lapor")
    public int idLapor;

    @ColumnInfo(name = "id_satuan")
    public int idSatuan;

    @ColumnInfo(name = "nama_ibadah")
    public String namaIbadah;

    @ColumnInfo(name = "satuan_ibadah")
    public String satuanIbadah;

    @ColumnInfo(name = "target_ibadah")
    public boolean targetIbadah;

    @ColumnInfo(name = "catat_ibadah")
    public boolean catatIbadah;

    @ColumnInfo(name = "lapor_ibadah")
    public boolean laporIbadah;

    @ColumnInfo(name = "et_target")
    public String etTarget;

    @ColumnInfo(name = "et_capaian")
    public String etCapaian;

    @ColumnInfo(name = "status")
    public boolean status;

    public int getIdSimpan() {
        return idSimpan;
    }

    public void setIdSimpan(int idSimpan) {
        this.idSimpan = idSimpan;
    }

    public int getIdIbadahJoin() {
        return idIbadahJoin;
    }

    public void setIdIbadahJoin(int idIbadahJoin) {
        this.idIbadahJoin = idIbadahJoin;
    }

    public int getIdPeriode() {
        return idPeriode;
    }

    public void setIdPeriode(int idPeriode) {
        this.idPeriode = idPeriode;
    }

    public int getIdTarget() {
        return idTarget;
    }

    public void setIdTarget(int idTarget) {
        this.idTarget = idTarget;
    }

    public int getIdCatat() {
        return idCatat;
    }

    public void setIdCatat(int idCatat) {
        this.idCatat = idCatat;
    }

    public int getIdLapor() {
        return idLapor;
    }

    public void setIdLapor(int idLapor) {
        this.idLapor = idLapor;
    }

    public int getIdSatuan() {
        return idSatuan;
    }

    public void setIdSatuan(int idSatuan) {
        this.idSatuan = idSatuan;
    }

    public boolean isTargetIbadah() {
        return targetIbadah;
    }

    public void setTargetIbadah(boolean targetIbadah) {
        this.targetIbadah = targetIbadah;
    }

    public boolean isCatatIbadah() {
        return catatIbadah;
    }

    public void setCatatIbadah(boolean catatIbadah) {
        this.catatIbadah = catatIbadah;
    }

    public boolean isLaporIbadah() {
        return laporIbadah;
    }

    public void setLaporIbadah(boolean laporIbadah) {
        this.laporIbadah = laporIbadah;
    }

    public String getEtTarget() {
        return etTarget;
    }

    public void setEtTarget(String etTarget) {
        this.etTarget = etTarget;
    }

    public String getEtCapaian() {
        return etCapaian;
    }

    public void setEtCapaian(String etCapaian) {
        this.etCapaian = etCapaian;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getNamaIbadah() {
        return namaIbadah;
    }

    public void setNamaIbadah(String namaIbadah) {
        this.namaIbadah = namaIbadah;
    }

    public String getSatuanIbadah() {
        return satuanIbadah;
    }

    public void setSatuanIbadah(String satuanIbadah) {
        this.satuanIbadah = satuanIbadah;
    }
}

IbadahDAO.java

@Dao
public interface IbadahDAO {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insertIbadah (Ibadah ibadah);

    @Update
    int updateIbadah (Ibadah ibadah);

    @Delete
    int deleteIbadah (Ibadah ibadah);

    @Insert (onConflict = OnConflictStrategy.REPLACE)
    long insertTarget (Ibadah ibadah);

    @Insert (onConflict = OnConflictStrategy.REPLACE)
    long insertCapai (Ibadah ibadah);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insertNamaTarget (NamaTarget namaTarget);

    @Update
    int updateNamaTarget (NamaTarget namaTarget);

    @Delete
    int deleteNamaTarget (NamaTarget namaTarget);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insertIbadah (NamaTarget namaTarget);

    @Update
    int updateIbadah (NamaTarget namaTarget);

    @Insert (onConflict = OnConflictStrategy.REPLACE)
    long insertTarget (NamaTarget namaTarget);

    @Insert (onConflict = OnConflictStrategy.REPLACE)
    long insertCapai (NamaTarget namaTarget);

    @Insert (onConflict = OnConflictStrategy.REPLACE)
    long insertDataTarget (SimpanTarget simpanTarget);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insertIbadah (SimpanTarget simpanTarget);

    @Update
    int updateIbadah (SimpanTarget simpanTarget);

    @Query("SELECT * FROM ttarget WHERE nama_target = nama_target")
    NamaTarget[] selectAllNamaTargets();

    @Query("SELECT * FROM tibadah")
    Ibadah[] selectAllStatus();

    @Query("SELECT * FROM tibadah")
    Ibadah[] selectAllIbadahs();

    @Query("SELECT * FROM tibadah WHERE idIbadah = :id LIMIT 1")
    Ibadah selectIbadahDetail(int id);

    @Query("SELECT * FROM ttarget WHERE idTarget = :id LIMIT 1")
    NamaTarget selectPeriodeDetail(int id);

    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
    @Query("SELECT tabjoin.idSimpan, tibadah.nama_ibadah " +
            "FROM tabjoin, tibadah " +
            "WHERE tabjoin.id_ibajoin = tibadah.nama_ibadah ")
    SimpanTarget[] selectAllIbadahJoin();
}

所以我的问题是我何时要使用此代码加入该表

  

@Query(“ SELECT tabjoin.idSimpan,tibadah.nama_ibadah” +               “ FROM tabjoin,提巴达” +               “”在哪里tabjoin.id_ibadah = tibadah.nama_ibadah“)

     

SimpanTarget [] selectAllIbadahJoin();

然后显示此错误

  

错误:查询返回的列没有字段   [idabad,idperiode,idTarget,idCatat,idLapor,idSatuan,targetIbadah,catalogIbadah,laporIbadah,状态]   在skripsi.com.ggr.managementibadah.model.SimpanTarget中   即使它们被注释为非null或原始类型。

     

查询返回的列:[idSimpan,nama_ibadah]

我感觉到显示错误是因为我不关联表吗?真的吗?如果不是,该如何解决该错误?我希望你能帮助我。 非常感谢您,我的英语不好。

1 个答案:

答案 0 :(得分:0)

与关系无关。错误消息基本上说:在查询中,您仅选择tabjoin.idSimpantibadah.nama_ibadah;并且您尝试返回类型为SimpanTarget的数组。这两个字段不足以创建SimpanTarget实例。您应该改为选择整个字段集。例如:SELECT tabjoin.*