msg:Cannot find the getter for attribute 'andr

2019-05-03 09:49发布

问题:

I am trying to use data binding in the edittext, In the morning it is working fine but suddenly got the error:

****/ data binding error ****msg:Cannot find the getter for attribute 'android:text' with value type java.lang.String on android.widget.EditText. file:/home/itstym/ApkProjects/Reminder/app/src/main/res/layout/activity_main.xml loc:20:4 - 34:40 ****\ data binding error ****

EditText at line 20:4 -34:40

 <EditText
        app:error="@{login.errorEmail}"
        android:text="@={login.userEmailAddress}"
        android:hint="Email Address"
        android:id="@+id/email_address"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="24dp"/>

View Holder:

 @Bindable
var userEmailAddress:String = String()
    set(userEmailAddress){
        field=userEmailAddress
        notifyPropertyChanged(R.id.email_address)
        /*to check Email for validation on every character inserted by user*/
        notifyPropertyChanged(BR.errorEmail)
    }
    get() {
    return field
}

What went suddenly wrong?

Solution tried: 1. Invalidate cache and restart. 2. Clean project and Rebuild project.

回答1:

Remove get() method from userEmailAddress as Kotlin provide Synthetic property access in it, you can direct access userEmailAddress without get()



回答2:

I'd like to bring the answer from another post here (courtesy of Matej Drobnič) :

"I just had that issue and I have managed to solve it by deleting .idea, .gradle and gradle folders and let Android Studio recreate whole project from scratch from gradle files."

I have run into this problem many times. It always involves some cleaning, deleting, restarting. For me, this answer is probably the most reliable way to remedy this flaw of Android Studio.