Error using databinding in android

后端 未结 12 890
情深已故
情深已故 2020-12-16 09:45

I am trying to test data binding as given in the guide here. I have included this in my build.gradle file (of module app) :

compileSdkVersion \'android-MNC\         


        
12条回答
  •  庸人自扰
    2020-12-16 10:14

    You have to be very careful that your POJO class data members should be public if you are not creating the getter setters.

    If you have simple POJO without any getter or setter

    public class User {
       public final String firstName;
       public final String lastName;
       public User(String firstName, String lastName) {
           this.firstName = firstName;
           this.lastName = lastName;
       }
    }
    

    If you make getter setter, javaBean style class

    public class User {
       private final String firstName;
       private final String lastName;
       public User(String firstName, String lastName) {
           this.firstName = firstName;
           this.lastName = lastName;
       }
       public String getFirstName() {
           return this.firstName;
       }
       public String getLastName() {
           return this.lastName;
       }
    }
    

提交回复
热议问题