xml布局文件和视图持有人都是正确的,因此我仍然不知道为什么会收到此错误。
我的同事们都已经仔细检查过了。我创建了一个包含应用程序模块的模块,现在出现此错误。
我将不胜感激任何想法或帮助!
错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':apk_holder:compileBetaDebugJavaWithJavac'.
> java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Could not find accessor com.laurence.ui.TitleMvvm.ViewModel.onClick and java.lang.Object has 0 abstract methods, so is not resolved as a listener
file:D:\laur\Documents\Apps\TestApp\app\src\main\res\layout\title.xml
loc:17:23 - 17:33
****\ data binding error ****
****/ data binding error ****msg:Could not find accessor com.laurence.ui.NotesMvvm.ViewModel.onClick and java.lang.Object has 0 abstract methods, so is not resolved as a listener
file:D:\laur\Documents\Apps\TestApp\app\src\main\res\layout\activity_notes.xml
loc:21:23 - 21:33
loc:61:27 - 61:37
****\ data binding error ****
****/ data binding error ****msg:Could not find accessor com.laurence.ui.SplashMvvm.ViewModel.onClick and java.lang.Object has 0 abstract methods, so is not resolved as a listener
file:D:\laur\Documents\Apps\TestApp\app\src\main\res\layout\activity_splash.xml
loc:26:31 - 26:52
****\ data binding error ****
****/ data binding error ****msg:Could not find accessor com.laurence.ui.NewMvvm.ViewModel.onClick and java.lang.Object has 0 abstract methods, so is not resolved as a listener
file:D:\laur\Documents\Apps\TestApp\app\src\main\res\layout\fragment_new.xml
loc:31:35 - 31:52
****\ data binding error ****
title.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="vm"
type="com.laurence.ui.TitleMvvm.ViewModel" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:onClick="@{vm::onClick}">
</android.support.constraint.ConstraintLayout>
</layout>
TitleScreen.kt
interface TitleMvvm {
interface View : MvvmView
interface ViewModel : MvvmViewModel<View>{
@get:Bindable
val isClickableSection: Boolean
fun onClick()
}
}
class TitleDelegate : BaseActivity<TitleViewHolder> {
override fun createViewHolder(parent: ViewGroup): TitleViewHolder = Utils.createViewHolder(parent, R.layout.title, ::TitleViewHolder)
override fun bindViewHolder(viewHolder: TitleViewHolder, list: List<SectionItem>, position: Int) {
viewHolder.viewModel.update(list[position])
}
}
class TitleViewHolder constructor(itemView: View) : BaseViewHolder<TitleBinding, TitleMvvm.ViewModel>(itemView), TitleMvvm.View {
init {
viewHolderComponent.inject(this)
bindContentView(itemView)
}
}
@PerViewHolder
open class TitleViewModel
@Inject
constructor(private var navigator: Navigator,
private var urlHandler: UrlHandler) : BaseViewModel<TitleMvvm.View>(), TitleMvvm.ViewModel {
override fun onClick() {
if (isClickableSection) {
// yet to do something
}
}
}
答案 0 :(得分:1)
遇到同样的问题。
因此解决方案是更改为项目视图-> 删除/删除 .Gradle
和.idea
文件夹->重建项目->完成>
将app:onClick="@{vm::onClick}"
替换为android:onClick="@{vm::onClick}"