在布局中添加了一些引用后,这些视图会从我的viewmodel中引用LiveData对象,从而开始出现数据绑定错误。我已经在其他布局中做了很多次,但是我从来没有遇到过这个问题。该错误并不能说明什么地方出了问题。
这是错误消息
CheckoutBindingImpl.java:57: error: cannot find symbol
java.lang.String callbackArg_0 = android.databinding.adapters.TextViewBindingAdapter.getTextString(firstName);
^
symbol: variable databinding
location: variable android of type Button
/home/Droids/vv/sample-app/app/build/generated/source/kapt/stageCheckoutDebug/com/sample/databinding/FragmentCheckoutBindingImpl.java:685: error: cannot find symbol
android.databinding.adapters.TextViewBindingAdapter.setTextWatcher(this.firstName, (android.databinding.adapters.TextViewBindingAdapter.BeforeTextChanged)null, (android.databinding.adapters.TextViewBindingAdapter.OnTextChanged)null, (android.databinding.adapters.TextViewBindingAdapter.AfterTextChanged)null, firstNameandroidTextAttrChanged);
^
symbol: variable databinding
location: variable android of type Button
/home/Droids/vv/sample-app/app/build/generated/source/kapt/stageCheckoutDebug/com/sample/databinding/FragmentCheckoutBindingImpl.java:713: error: cannot find symbol
android.databinding.adapters.TextViewBindingAdapter.setText(this.firstName, viewModelFirstNameGetValue);
^
symbol: variable databinding
location: variable android of type Button
Note: /home/Droids/vv/sample-app/app/build/generated/source/kapt/stageCheckoutDebug/com/sample/injection/DaggerAppComponent.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
这是布局的一部分:
<EditText
android:id="@+id/first_name"
style="@style/CheckoutInputField"
android:layout_width="0dp"
android:layout_height="@dimen/checkout_edit_text_height"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:inputType="textPersonName"
android:text="@={viewModel.firstName}"
app:layout_constraintEnd_toStartOf="@+id/last_name"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/first_label" />
这是视图模型:
abstract class CheckoutViewModel : ViewModel() {
abstract var cartNavigator: CartNavigator?
abstract val firstName: MutableLiveData<String>
/* other stuff *
}
viewmodel实现很简单:
class CheckoutViewModelImpl @Inject constructor(
private val schedulerProvider: SchedulerProvider
) : CheckoutViewModel() {
override val firstName = MutableLiveData<String>()
/* other stuff *
}
这是自动生成类的一部分,其中抛出了一个错误(与android.databinding.adapters一致):
if ((dirtyFlags & 0x800L) != 0) {
// api target 1
this.android.setOnClickListener(mCallback58);
this.apple.setOnClickListener(mCallback59);
this.back.setOnClickListener(mCallback55);
this.debitCredit.setOnClickListener(mCallback56);
android.databinding.adapters.TextViewBindingAdapter.setTextWatcher(this.firstName, (android.databinding.adapters.TextViewBindingAdapter.BeforeTextChanged)null, (android.databinding.adapters.TextViewBindingAdapter.OnTextChanged)null, (android.databinding.adapters.TextViewBindingAdapter.AfterTextChanged)null, firstNameandroidTextAttrChanged);
this.paypal.setOnClickListener(mCallback57);
}
这也是自动生成文件中的错误之一的屏幕截图:
关于此问题可能有什么建议?
答案 0 :(得分:0)
对于所有遇到此错误的用户,请确保您没有将android:id意外设置为“ @ + id / android”。在我的情况下,ID设置为android。 更改ID后,错误已修复。