While using data binding , I am not able to get class MainActivityBinding
as per Data Binding Guide
My layout name is activity_main.xml
.
I
I also faced same issue. But after updating android to androidx solved like
try to change android.databinding.... to androidx.databinding...
If DataBinding class name is correct and you used to clean and rebuild project but it still show error.
Then you try to restart AndroidStudio
I've cleaned the project , Rebuild was done...but of no use. Then invalidated caches and restarted the project that too didn't helped me.
Then I changed my xml file name - that worked fantastically fine.
So, I would like to share you one thing, please change your xml file name.
For eg: If your xml file is: activity_main.xml and you can't get ActivityMainBinding in its Java class..........then change xml name to main_activity.xml and then use MainActivityBinding in its java class as 'private MainActivityBinding binding;'
This will do most probably.
try to review your xml, if has a value which was setted wrong. This is probably something about wrong databinding settings
Check that you activity/fragment's xml and class have consistent names; for example, if you have TimePickerFragment
than xml file name should be time_picker_fragment
.
It occurred to me that I had the layout named fragment_time_picker
; after I changed it the binding was generated.
In such cases, if neither rebuild nor invalidate caches work, then there must be an error in one of your xml files where you may have used @{xyz.abc} and there must be a problem with either xyz or abc in the xml.