我用谷歌搜索但仍然没有找到适合我的解决方案。
这是我的 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>
这是我的视图模型代码:
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);
}
}
但是当我尝试运行我的应用程序时,我得到了它:
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
地点:44:33 - 44:62
****\ 数据绑定错误 ****
附:在我的应用程序的其他地方它可以工作,但我遇到了问题。
尝试改变<import>
标记到一个<variable>
tag:
<data>
<variable
name="noteViewModel"
type="com.app.screen.createnote.CreateNoteViewModel" />
</data>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)