我启用了数据绑定,但是在执行代码时出现此错误。
e:[kapt]发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误。
我创建了一个片段类和该类的XML。我能够导入datbindingutil类。
我已经完成了重建/与gradle文件同步/使缓存无效并重新启动,没有任何效果。
<layout>
<!--suppress AndroidUnknownAttribute -->
<data class=".databinding.ProfileFragmentBinding">
<variable
name="user"
type="com.sample.sample.user.User" />
<variable
name="vm"
type="com.sample.sample.user.UserViewModel" />
<variable
name="handler"
type="com.sample.sample.user.profile.ProfileFragment" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profileIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/medium"
android:layout_marginTop="@dimen/medium"
android:contentDescription="@null"
android:src="@mipmap/ic_launcher_round"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:url="@{user.avatarUrl}" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/profileIV"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/profileIV">
<TextView
android:id="@+id/profileNameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/myriad_pro_semibold"
android:text="@{user.name}"
android:textColor="@color/black_transparent_de"
android:textSize="@dimen/text_regular"
tools:text="NAME" />
<TextView
android:id="@+id/badgeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="@font/myriad_pro_semibold"
android:text="@{user.badge}"
android:textColor="@color/grey_000000"
android:textSize="@dimen/text_regular"
tools:text="Superman" />
<TextView
android:id="@+id/profile_Label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="@font/roboto_bold"
android:text="@{user.badge}" …Run Code Online (Sandbox Code Playgroud) 我试图在edittext中使用数据绑定,在早上它工作正常,但突然得到错误:
****/ 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 ****
Run Code Online (Sandbox Code Playgroud)
EditText在第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"/>
Run Code Online (Sandbox Code Playgroud)
查看持有人:
@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
}
Run Code Online (Sandbox Code Playgroud)
什么突然错了?
尝试解决方案:1.使缓存无效并重新启动.2.清理项目和重建项目.
android 2-way-object-databinding kotlin android-databinding two-way-binding