1.問題描述
使用databinding玩裙,然后使用BindingAdapter自定義方法兼贸,在xml文件中引用,結果打開APP后閃退吃溅。并報如下錯誤信息:
java.lang.IllegalStateException: Required DataBindingComponent is null in class ItemTaskCateBindingImpl. A BindingAdapter in com.zhangy.common_dear.manager.DataBindingManager is not static and requires an object to use, retrieved from the DataBindingComponent. If you don't use an inflation method taking a DataBindingComponent, use DataBindingUtil.setDefaultComponent or make all BindingAdapter methods static.
自定義方法如下:
image.png
2.解決方法
根據提示可知溶诞,原因是沒有使用static修飾這個方法,這個方法沒法在xml中調用决侈,因為不是靜態(tài)方法螺垢。解決方法就是在設置為static。
image.png