Please someone help me! I am going crazy, this should work. I have the following error message when I try to build my Android project:
Android resource linking failed
/Users/slehrbaum/StudioProjects/OneNightComps/Android/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_login.xml:17: error: attribute errorText (aka lehrbaum.de.onenightcomps:errorText) not found.
error: failed linking file resources.
the error message does mention the errorText attribute. I use the errorText attribute in the xml this way (full xml here):
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/usernameField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
app:hintEnabled="true"
app:errorEnabled="true"
app:errorText="Hi"
>
<!--app:errorText="Please provide a username."-->
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="username"
android:inputType="text"
android:text="@={viewModel.username}"
/>
</com.google.android.material.textfield.TextInputLayout>
This is the way I have defined errorText in my Kotlin file (full file here):
object ViewDataBindingExtensions {
@JvmStatic
@BindingAdapter("errorText")
fun bindErrorText(textInputLayout: TextInputLayout, errorText: String) {
textInputLayout.error = errorText
}
}
I just don't understand why this happens. Is there some sort of import that I can put in the layout file saying where the BindingAdapter is? Do I have some wrong with my Gradle files? I compared it to the GitHub project in this question which apparently got solved and I do not see the difference to my project. According to the answer I should add the Kotlin-kapt plugin to my Gradle build, which I did. I also looked through the rest of the project and compared. To no avail. You can find my whole build.gradle file here as well as the rest of the project.
Please help me!
Binding adapters are responsible for making the appropriate framework calls to set values. One example is setting a property value like calling the setText() method. Another example is setting an event listener like calling the setOnClickListener() method.
Using data binding can lead to faster development times, faster execution times and more readable and maintained code. Android data binding generates binding classes at compile time for layouts.
The problem is connected with the way you pass String value to app:errorText
.
Use @{``} to pass this value.
Fixed part of fragment_login.xml:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
app:hintEnabled="true"
app:errorText="@{`Please provide a username.`}"
app:errorEnabled="@{!viewModel.usernameValid}">
Having apply plugin: 'kotlin-kapt'
in app/build.gradle
is mandatory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With