我在使用Integer数据类型实现双向绑定时遇到了一些问题.
public class User {
private String firstName;
private String lastName;
private int age;
public User() {}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return this.firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return this.lastName;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return this.age;
}
}
XML:
name="user"
type="com.databinding.model.User" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">
android:layout_height="wrap_content"
android:text="@={user.firstName}" />
android:layout_height="wrap_content"
android:text="@={user.lastName}" />
android:layout_height="wrap_content"
android:text="@={user.age}" />
不幸的是,它给了我错误
“Error:(52, 17) Cannot find the getter for attribute ‘android:text’
with value type java.lang.Integer on
android.support.design.widget.TextInputEditText. “
如果我将属性文本更改为
android:layout_height="wrap_content"
android:text="@={Integer.toString(user.age)}" />
然后我得到了错误
“Error:cannot generate view binders java.lang.NullPointerException”
感谢任何帮助.
更新:似乎在上面提到的错误之后发生了另一个错误.
cannot generate view binders java.lang.NullPointerException
不知道为什么它给我NPE即使应用还没有开始.