数据绑定错误-找不到访问器 [英] Databinding error - Could not find accessor

查看:95
本文介绍了数据绑定错误-找不到访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Google搜索,但仍然找不到适合我的解决方案.

I googled but still didn't find solution for me.

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <data>
        <import
            alias="noteViewModel"
            type="com.app.screen.createnote.CreateNoteViewModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <EditText
                android:id="@+id/etNote"
                style="@style/JWidget.EditText.Grey"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="start"
                android:inputType="textMultiLine"
                android:scrollbars="vertical"
                android:text="@={noteViewModel.note.description}" />        
    </LinearLayout>
</layout>

这是我的ViewModel代码:

This is my ViewModel code:

public class CreateNoteViewModel extends BaseObservable {
     private Note note;
     @Bindable
     public Note getNote() {
         return note;
     }

     public void setNote(Note note) {
         this.note = note;
         notifyPropertyChanged(BR.note);
     }

}

但是当我尝试运行我的应用程序时,我得到了它:

But when I try run my app I got it:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

java.lang.RuntimeException:发现数据绑定错误. ****/数据绑定错误**** msg:找不到访问器com.justsafe.tmgr.justsafe.screen.createnote.CreateNoteViewModel.note 文件:C:\ android \ work \ JustSafeTmgr \ app \ src \ main \ res \ layout \ activity_create_note.xml loc:44:33-44:62 **** \数据绑定错误****

java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Could not find accessor com.justsafe.tmgr.justsafe.screen.createnote.CreateNoteViewModel.note file:C:\android\work\JustSafeTmgr\app\src\main\res\layout\activity_create_note.xml loc:44:33 - 44:62 ****\ data binding error ****

P.S.在我的应用程序的其他地方,它可以正常工作,但是我遇到了问题.

P.S. In other place in my app it work, but there I get problem.

推荐答案

尝试将<import>标记更改为<variable>标记:

Try to change the <import> tag to a <variable> tag:

<data>
        <variable
            name="noteViewModel"
            type="com.app.screen.createnote.CreateNoteViewModel" />
    </data>

这篇关于数据绑定错误-找不到访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆