2017-10-05 67 views
0

我是android架構組件中的新成員。我正在嘗試與android-architecture-components/BasicRxJavaSample以及Gradle配置一起構建應用程序。但我得到以下錯誤:錯誤:實體和Pojos必須有一個可用的公共構造函數,並且無法找到字段的設置器

  • 錯誤:(14,8)錯誤:實體和Pojos必須有一個可用的公共構造函數。你可以有一個空的構造函數或者一個構造函數,它們的參數匹配字段(通過名稱和類型)。嘗試使用下列構造函數,但它們不匹配:= Department(java.lang.String,java.lang.String):[id: null,dep:null]
  • 錯誤:(16,20)錯誤:無法找到字段的setter。
  • 錯誤:(18,20)錯誤:無法找到字段的setter。

我對所有體系結構組件使用「1.0.0-alpha9」版本。我也嘗試過使用當前的「1.0.0-beta1」版本。

我看了[曖昧的getter for Field ...房間持久性庫 2鏈接也可以根據谷歌示例不需要爲每個字段設置。

Model類

@Entity(tableName = "tblDepartment") 
public class Department{ 
    @PrimaryKey 
    private String mId; 

    private String mName; 

    @Ignore 
    public Department(String dep) { 
     mId= UUID.randomUUID().toString(); 
     mName= dep; 
    } 
    public Department(String id, String dep) { 
     mId = id; 
     mName=dep; 
    } 

    public String getDepartmentId() { 
     return mId; 
    } 

    public String getDepartmentName() { 
     return mName; 
    } 
} 
+0

你的問題是與'Expense'類。你的問題顯示了一個'部門'類。要麼你有錯誤的錯誤信息或錯誤的代碼。 – CommonsWare

+0

我錯誤地添加了錯誤的錯誤日誌。 –

回答

0

你需要一個有效的構造槽的名字。

並且您正在存儲槽的所有字段的吸氣劑/吸附劑室。

嘗試:

@Entity(tableName = "tblDepartment") 
public class Department{ 
@PrimaryKey 
private String mId; 

private String mName; 

@Ignore 
public Department(String mName) { 
    mId= UUID.randomUUID().toString(); 
    this.mName= mName; 
} 
public Department(String id, String name) { 
    this.mId = mId; 
    this.mName=mName; 
} 

public String getId() { 
    return mId; 
} 

public String getName() { 
    return mName; 
} 
public void setId(String mId){ this.mId = mId; } 
public void setName(String mName){ this.mName = mName; } 
} 
+0

[檢查此谷歌示例](https://github.com/googlesamples/android-architecture-components/blob/master/BasicRxJavaSample/app/src/main/java/com/example/android/observability/persistence/User。 java)。這裏沒有使用公共構造函數。 –

+0

我已經嘗試過這個構造函數。 –

+1

問題是你不使用列名稱和你的POJO沒有在你的變量中有相同的名稱你的變量 –

相關問題