I got the same error as the title.
When I try to set an image on glideSrc
using databinding
, an error occurs.
Cannot find a setter for <android.widget.ImageView app:glideSrc> that accepts parameter type 'int'
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
In order to solve the error, I added the kapt plug-in
as in the answers to other similar questions. LINK
However, it still causes the same error.
In fact, most of the data binding codes, as well as the xml code above, cause that error.
How do you solve this problem?
gradle.app
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
id("androidx.navigation.safeargs")
id("kotlin-kapt")
}
android {
namespace = "com.example.materialcomponentsmotion"
compileSdk = 34
defaultConfig {
applicationId = "com.example.materialcomponentsmotion"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildFeatures {
dataBinding = true
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
val nav_version = "2.7.7"
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
implementation("com.github.bumptech.glide:glide:4.13.0")
kapt("com.github.bumptech.glide:compiler:4.13.0")
}
xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="email"
type="com.example.materialcomponentsmotion.data.Email" />
</data>
<androidx.core.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:paddingHorizontal="@dimen/grid_0_5"
android:paddingTop="@dimen/grid_1"
android:clipToPadding="false"
android:background="?android:colorBackground">
<com.google.android.material.card.MaterialCardView
android:id="@+id/email_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:transitionName="@string/email_card_detail_transition_name">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/menu_item_constraint_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/grid_2"
android:paddingTop="@dimen/grid_3"
android:paddingBottom="@dimen/bottom_app_bar_height">
<ImageView
android:id="@+id/sender_profile_image_view"
android:layout_width="@dimen/email_sender_profile_image_size"
android:layout_height="@dimen/email_sender_profile_image_size"
android:contentDescription="@string/email_sender_profile_content_desc"
android:scaleType="centerCrop"
app:glideSrc="@{email.sender.avatar}"
app:layout_constraintTop_toTopOf="@id/sender_text_view"
app:layout_constraintBottom_toBottomOf="@+id/recipient_text_view"
app:layout_constraintEnd_toEndOf="parent"
tools:src="@drawable/avatar_3" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.core.widget.NestedScrollView>
</layout>
Email.kt
data class Email(
val id: Long,
val sender: Account,
val recipients: List<Account> = emptyList(),
val subject: String = "",
val body: String = "",
val attachments: List<EmailAttachment> = emptyList(),
var isImportant: Boolean = false,
var isStarred: Boolean = false,
var mailbox: Mailbox = Mailbox.INBOX
) {
val senderPreview: String = "${sender.fullName} - 4 hrs ago"
val hasBody: Boolean = body.isNotBlank()
val hasAttachments: Boolean = attachments.isNotEmpty()
val recipientsPreview: String = recipients
.map { it.firstName }
.fold("") { name, acc -> "$acc, $name" }
val nonUserAccountRecipients = recipients
.filterNot { AccountStore.isUserAccount(it.uid) }
}
Account
data class Account(
val id: Long,
val uid: Long,
val firstName: String,
val lastName: String,
val email: String,
val altEmail: String,
@DrawableRes val avatar: Int,
var isCurrentAccount: Boolean = false
) {
val fullName: String = "$firstName $lastName"
@DrawableRes val checkedIcon: Int = if (isCurrentAccount) R.drawable.ic_done else 0
}