当我尝试运行我的应用程序时出现以下错误:
Error:Execution failed for task ':app:compileDevelopmentDebugJavaWithJavac'.
> java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Could not find accessor java.lang.String.giftRecipientName redacted.xml loc:182:63 - 182:93 ****\ data binding error ****
我有一个 Order 对象,如下所示:
public class Order {
public Address address;
// unrelated fields and methods
}
嵌套的 Address 对象如下所示:
public class Address {
public String addressLine1;
public String addressLine2;
public String giftRecipientName;
public Boolean isGift;
}
在我的 .xml 中,我正在执行以下操作:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="order" type="example.redacted.models.Order"/>
</data>
// widgets and whatnot
<TextView
android:id="@+id/gift_recipientTV"
android:layout_column="1"
android:layout_weight="1"
android:layout_width="0dp"
android:textStyle="bold"
android:gravity="right"
android:text='@{order.address.isGift ? order.address.giftRecipientName : "" }'/>
最后在我的片段中:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
RedactedBinding dataBinding = DataBindingUtil.inflate(inflater, R.layout.redacted, container, false);
dataBinding.setOrder(_order);
return dataBinding.getRoot();
}