![](/img/trans.png)
[英]Android data binding : Cannot find setter for attribute app:list
[英]Android Data Binding BindingAdapter: “Cannot find the setter”
此綁定屬性無法構建,並顯示以下錯誤:
找不到屬性“ errorText”的設置器
@BindingAdapter({"errorText"})
public static void setErrorText(TextInputLayout view, String error) {
view.setError(error);
}
<android.support.design.widget.TextInputLayout
android:id="@+id/email_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:errorEnabled="true"
app:errorText="@{data.usernameError}"
>
....
為什么這不起作用?
似乎是由於完全不相關的代碼中其他地方的源錯誤導致未編譯BindingAdapter引起此錯誤。 在構建錯誤日志中還不清楚其他源錯誤(使用不同名稱聲明了錯別字,因此引用了變量,因此不存在),但是一旦我在源代碼中看到它,就很容易修復,反過來修復了BindingAdapter問題。
如果看到此錯誤,請檢查源和構建日志中是否存在其他可能的構建錯誤。
首先, setErrorText
是公共的,因此您不需要在binding adapter
定義。 在BindingAdapter類中沒有定義errorText
情況下仍然可以正常工作(已確認!)
如果要在綁定適配器中定義,則必須進行如下更改:
@BindingAdapter("app:errorText")
希望對您有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.