Caused by: java.lang.IllegalArgumentException: couldn't make a guess for com.example.example.databinding.ContentClassApplicationMyClass1Binding

回眸只為那壹抹淺笑 提交于 2019-12-01 04:00:48

Its because of you class name or package name which use databinding. These class( which use databinding) have to start with capital word and packages start with lowercase.

The reason for this error is, as Mehdi already stated in his answer, the capitalization in the Java package name of the binding and variable classes.

When further examining the logs, you can see that the error gets thrown at ClassName.bestGuess(String). The reason is that the package name of your bound classes, aka the ones in the <variable> field in your layout, contain uppercase characters in their package name. This causes the method to not be able to separate the Class name from the package name, and it throws an error.
[to be honest, that's a rather poor behavior, but probably no better way exists (yet)]

The same is true for the generated binding class, it also needs to be in a package that doesn't have any uppercase letters in it. As it uses your app package name by default, you have to change the java package name by adding the class property to the <data> field in your layout (Read more here).

Example:

<layout xmlns:app="http://schemas.android.com/apk/res-auto">
    <data class="com.example.ExampleDataBinding">
        <variable
            name="example"
            type="com.example.ExampleClass" />
    </data>
</layout>

The Binding class name seems to be wrong. Can you try changing it from ActivityClassApplicationMyClass1Binding to ActivityClassApplicationMyclass1Binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!