Android DataBinding error. Could not find accessor











up vote
12
down vote

favorite
1












I'm getting the following error when I try to run my app:



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


I have an Order object which looks like this:



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


The nested Address object looks like this:



public class Address {
public String addressLine1;
public String addressLine2;
public String giftRecipientName;
public Boolean isGift;
}


In my .xml I am doing the following:



<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 : "" }'/>


Lastly in my fragment:



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









share|improve this question


























    up vote
    12
    down vote

    favorite
    1












    I'm getting the following error when I try to run my app:



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


    I have an Order object which looks like this:



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


    The nested Address object looks like this:



    public class Address {
    public String addressLine1;
    public String addressLine2;
    public String giftRecipientName;
    public Boolean isGift;
    }


    In my .xml I am doing the following:



    <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 : "" }'/>


    Lastly in my fragment:



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









    share|improve this question
























      up vote
      12
      down vote

      favorite
      1









      up vote
      12
      down vote

      favorite
      1






      1





      I'm getting the following error when I try to run my app:



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


      I have an Order object which looks like this:



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


      The nested Address object looks like this:



      public class Address {
      public String addressLine1;
      public String addressLine2;
      public String giftRecipientName;
      public Boolean isGift;
      }


      In my .xml I am doing the following:



      <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 : "" }'/>


      Lastly in my fragment:



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









      share|improve this question













      I'm getting the following error when I try to run my app:



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


      I have an Order object which looks like this:



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


      The nested Address object looks like this:



      public class Address {
      public String addressLine1;
      public String addressLine2;
      public String giftRecipientName;
      public Boolean isGift;
      }


      In my .xml I am doing the following:



      <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 : "" }'/>


      Lastly in my fragment:



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






      android data-binding android-databinding






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 20 '15 at 19:04









      MidasLefko

      3,04312138




      3,04312138
























          4 Answers
          4






          active

          oldest

          votes

















          up vote
          17
          down vote



          accepted










          After hours of trial and error it seems that Android data-binding looks for getters before it looks at public fields. My Order object had a helper method called getAddress



          public class Order {
          public Address address;

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


          The binder was calling that method instead of accessing the public Address field. I put the getAddress method inside the Address object (where it probably should have been to begin with) and the app compiled.






          share|improve this answer




























            up vote
            1
            down vote














            Android DataBinding error. Could not find accessor





            • As this error tells, binding needs accessor or getter to work and also setter if you use two way binding.

            • So always put getter & setter in your model class.






            share|improve this answer




























              up vote
              1
              down vote













              In my case, My ViewModel has a variable name starting with m and it was creating a problem



              public class MyViewModel extends ViewModel {
              private LiveData<SomeClass> mTask; //Chaning the variable name to task and it's getter name to getTask worked for me
              //...code left for brevity
              public LiveData<SomeClass> getmTask() {
              return mTask;
              }
              }


              I changed the variable name mTask to task and it's getter name getmTask to getTask and it worked for me.



              public class MyViewModel extends ViewModel {
              private LiveData<SomeClass> task;
              //...code left for brevity
              public LiveData<SomeClass> getTask() {
              return task;
              }
              }


              And In my xml file I was able to access it



              <TextView
              ...
              android:text="@{viewmodel.task.title}"





              share|improve this answer




























                up vote
                1
                down vote













                Check your Layout file and ViewModel class. A variable name should be the same in both files.just like:



                In ViewModel class:



                MutableLiveData<String> emailId = new MutableLiveData<>();


                In Layout files:



                <EditText
                ........
                android:text="@={loginVM.emailId}"





                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32683129%2fandroid-databinding-error-could-not-find-accessor%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  17
                  down vote



                  accepted










                  After hours of trial and error it seems that Android data-binding looks for getters before it looks at public fields. My Order object had a helper method called getAddress



                  public class Order {
                  public Address address;

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


                  The binder was calling that method instead of accessing the public Address field. I put the getAddress method inside the Address object (where it probably should have been to begin with) and the app compiled.






                  share|improve this answer

























                    up vote
                    17
                    down vote



                    accepted










                    After hours of trial and error it seems that Android data-binding looks for getters before it looks at public fields. My Order object had a helper method called getAddress



                    public class Order {
                    public Address address;

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


                    The binder was calling that method instead of accessing the public Address field. I put the getAddress method inside the Address object (where it probably should have been to begin with) and the app compiled.






                    share|improve this answer























                      up vote
                      17
                      down vote



                      accepted







                      up vote
                      17
                      down vote



                      accepted






                      After hours of trial and error it seems that Android data-binding looks for getters before it looks at public fields. My Order object had a helper method called getAddress



                      public class Order {
                      public Address address;

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


                      The binder was calling that method instead of accessing the public Address field. I put the getAddress method inside the Address object (where it probably should have been to begin with) and the app compiled.






                      share|improve this answer












                      After hours of trial and error it seems that Android data-binding looks for getters before it looks at public fields. My Order object had a helper method called getAddress



                      public class Order {
                      public Address address;

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


                      The binder was calling that method instead of accessing the public Address field. I put the getAddress method inside the Address object (where it probably should have been to begin with) and the app compiled.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 20 '15 at 19:04









                      MidasLefko

                      3,04312138




                      3,04312138
























                          up vote
                          1
                          down vote














                          Android DataBinding error. Could not find accessor





                          • As this error tells, binding needs accessor or getter to work and also setter if you use two way binding.

                          • So always put getter & setter in your model class.






                          share|improve this answer

























                            up vote
                            1
                            down vote














                            Android DataBinding error. Could not find accessor





                            • As this error tells, binding needs accessor or getter to work and also setter if you use two way binding.

                            • So always put getter & setter in your model class.






                            share|improve this answer























                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote










                              Android DataBinding error. Could not find accessor





                              • As this error tells, binding needs accessor or getter to work and also setter if you use two way binding.

                              • So always put getter & setter in your model class.






                              share|improve this answer













                              Android DataBinding error. Could not find accessor





                              • As this error tells, binding needs accessor or getter to work and also setter if you use two way binding.

                              • So always put getter & setter in your model class.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 9 at 8:55









                              Khemraj

                              11.1k22867




                              11.1k22867






















                                  up vote
                                  1
                                  down vote













                                  In my case, My ViewModel has a variable name starting with m and it was creating a problem



                                  public class MyViewModel extends ViewModel {
                                  private LiveData<SomeClass> mTask; //Chaning the variable name to task and it's getter name to getTask worked for me
                                  //...code left for brevity
                                  public LiveData<SomeClass> getmTask() {
                                  return mTask;
                                  }
                                  }


                                  I changed the variable name mTask to task and it's getter name getmTask to getTask and it worked for me.



                                  public class MyViewModel extends ViewModel {
                                  private LiveData<SomeClass> task;
                                  //...code left for brevity
                                  public LiveData<SomeClass> getTask() {
                                  return task;
                                  }
                                  }


                                  And In my xml file I was able to access it



                                  <TextView
                                  ...
                                  android:text="@{viewmodel.task.title}"





                                  share|improve this answer

























                                    up vote
                                    1
                                    down vote













                                    In my case, My ViewModel has a variable name starting with m and it was creating a problem



                                    public class MyViewModel extends ViewModel {
                                    private LiveData<SomeClass> mTask; //Chaning the variable name to task and it's getter name to getTask worked for me
                                    //...code left for brevity
                                    public LiveData<SomeClass> getmTask() {
                                    return mTask;
                                    }
                                    }


                                    I changed the variable name mTask to task and it's getter name getmTask to getTask and it worked for me.



                                    public class MyViewModel extends ViewModel {
                                    private LiveData<SomeClass> task;
                                    //...code left for brevity
                                    public LiveData<SomeClass> getTask() {
                                    return task;
                                    }
                                    }


                                    And In my xml file I was able to access it



                                    <TextView
                                    ...
                                    android:text="@{viewmodel.task.title}"





                                    share|improve this answer























                                      up vote
                                      1
                                      down vote










                                      up vote
                                      1
                                      down vote









                                      In my case, My ViewModel has a variable name starting with m and it was creating a problem



                                      public class MyViewModel extends ViewModel {
                                      private LiveData<SomeClass> mTask; //Chaning the variable name to task and it's getter name to getTask worked for me
                                      //...code left for brevity
                                      public LiveData<SomeClass> getmTask() {
                                      return mTask;
                                      }
                                      }


                                      I changed the variable name mTask to task and it's getter name getmTask to getTask and it worked for me.



                                      public class MyViewModel extends ViewModel {
                                      private LiveData<SomeClass> task;
                                      //...code left for brevity
                                      public LiveData<SomeClass> getTask() {
                                      return task;
                                      }
                                      }


                                      And In my xml file I was able to access it



                                      <TextView
                                      ...
                                      android:text="@{viewmodel.task.title}"





                                      share|improve this answer












                                      In my case, My ViewModel has a variable name starting with m and it was creating a problem



                                      public class MyViewModel extends ViewModel {
                                      private LiveData<SomeClass> mTask; //Chaning the variable name to task and it's getter name to getTask worked for me
                                      //...code left for brevity
                                      public LiveData<SomeClass> getmTask() {
                                      return mTask;
                                      }
                                      }


                                      I changed the variable name mTask to task and it's getter name getmTask to getTask and it worked for me.



                                      public class MyViewModel extends ViewModel {
                                      private LiveData<SomeClass> task;
                                      //...code left for brevity
                                      public LiveData<SomeClass> getTask() {
                                      return task;
                                      }
                                      }


                                      And In my xml file I was able to access it



                                      <TextView
                                      ...
                                      android:text="@{viewmodel.task.title}"






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Oct 16 at 23:27









                                      L-X

                                      1,96311021




                                      1,96311021






















                                          up vote
                                          1
                                          down vote













                                          Check your Layout file and ViewModel class. A variable name should be the same in both files.just like:



                                          In ViewModel class:



                                          MutableLiveData<String> emailId = new MutableLiveData<>();


                                          In Layout files:



                                          <EditText
                                          ........
                                          android:text="@={loginVM.emailId}"





                                          share|improve this answer



























                                            up vote
                                            1
                                            down vote













                                            Check your Layout file and ViewModel class. A variable name should be the same in both files.just like:



                                            In ViewModel class:



                                            MutableLiveData<String> emailId = new MutableLiveData<>();


                                            In Layout files:



                                            <EditText
                                            ........
                                            android:text="@={loginVM.emailId}"





                                            share|improve this answer

























                                              up vote
                                              1
                                              down vote










                                              up vote
                                              1
                                              down vote









                                              Check your Layout file and ViewModel class. A variable name should be the same in both files.just like:



                                              In ViewModel class:



                                              MutableLiveData<String> emailId = new MutableLiveData<>();


                                              In Layout files:



                                              <EditText
                                              ........
                                              android:text="@={loginVM.emailId}"





                                              share|improve this answer














                                              Check your Layout file and ViewModel class. A variable name should be the same in both files.just like:



                                              In ViewModel class:



                                              MutableLiveData<String> emailId = new MutableLiveData<>();


                                              In Layout files:



                                              <EditText
                                              ........
                                              android:text="@={loginVM.emailId}"






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Nov 12 at 9:16









                                              Suraj Rao

                                              22.5k75469




                                              22.5k75469










                                              answered Nov 12 at 9:09









                                              rahul

                                              112




                                              112






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32683129%2fandroid-databinding-error-could-not-find-accessor%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Bressuire

                                                  Vorschmack

                                                  Quarantine