2015-09-20 9 views
8

एक्सेसर नहीं मिल सका मैं निम्न त्रुटि हो रही है जब मैं अपने अनुप्रयोग चलाने के लिए प्रयास करें:एंड्रॉइड डेटा बाइंडिंग त्रुटि।

public class Order { 
    public Address address; 
    // unrelated fields and methods 
} 

नेस्टेड पता वस्तु दिखता है: मैं एक आदेश वस्तु जो इस तरह दिखता है

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 **** 

इस तरह:

:

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(); 
} 

उत्तर

10

परीक्षण के घंटे के बाद और त्रुटि ऐसा लगता है कि टिककर खेल के लिए Android डेटा-बाइंडिंग दिखता से पहले ही सार्वजनिक क्षेत्रों में लग रहा है। माई ऑर्डर ऑब्जेक्ट में एक सहायक विधि थी जिसे GetAddress

public class Order { 
    public Address address; 

    public String getAddress() { 
     return address.addressLine1 + address.addressLine2; 
    } 
} 

बाइंडर सार्वजनिक पता फ़ील्ड तक पहुंचने के बजाय उस विधि को कॉल कर रहा था। मैंने पता ऑब्जेक्ट के अंदर getAddress विधि डाली (जहां शायद इसे शुरू करना चाहिए था) और ऐप संकलित किया गया था।

संबंधित मुद्दे