'Unknown DataBinding Class
I am newbie to DataBinding in Android and learning it to my own. I have just enabled the DataBinding in my App Gradle File in the Android Tag as:
dataBinding{
enabled=true
}
My XML is setup like this:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
tools:showIn="@layout/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
</RelativeLayout>
</layout>
And my Activity Looks like:
The problem is that the ActivityMainBinding Class is unknown to Android Studio. I don't know why is this happening. As I had clean, re-build make the project and everything doesn't help me out!
I am attaching an [screen shot][1] too, looking at the screenshot you can find that the ActivityMainBinding is highlighted in RED COLOR
Solution 1:[1]
It was totally strange because Its ANDROID STUDIO!
What I done is just changed the name of the activity_main.xml to activity_main_.xml then I make the project!
After Making the project, I reverted back to the old name i.e activity_main.xml and it works like a charm. Don't know but it works really because this GooF Android Studio doesn't even ever makes any sense!
Solution 2:[2]
It will only be named ActivityMainBinding
if your layout is named activity_main.xml
.
Solution 3:[3]
It's because you are using <layout>
attribute in content_main.xml. So your binding class name will be ContentMainBinding.
Also you need to set R.layout.content_main to DataBindingUtils class.
OR
Just add <layout>
in activity_main.xml and remove from content_main.xml and keep rest of code as it is. Just rebuild the project.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Java Nerd |
Solution 2 | terencey |
Solution 3 |