使用DataBinding時,不小心把DataBinding實現類命名搞成了這樣:mainView ,以小寫開頭了,結果出現了標題中的異常。使命名遵行類的命名規則編譯不會報錯。
報錯代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data class="mainView">
</data>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
正確的代碼:
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data class="MainView">
</data>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
注意 class="MainView"
和class="mainView"
的區別。