DataBinding Guide States
By default, a Binding class will be generated based on the name of the layout
file, converting it to Pascal case and suffixing “Bindi
If you ever wanted to give your own Binding class name just add class
attribute to the data
element with class name
Binding classes may be renamed or placed in different packages by adjusting the class attribute of the data element.
<data class="ContactItem">
...
</data>
<data class="com.example.ContactItem">
...
</data>
Faced the same issue.
Reason for "cannot resolve ActivityMainBinding" is that your Binding file isn't generated. Try to clean and rebuild project. Also make sure you have followed the steps :
Alternatively if you want to see the generated source.
These classes will be generated on first build. Also make sure the applicationId in your application module is same as the package name in AndroidManifest.xml of your app module. Hope this helps.
In my case Restarting Android Studio does work. It is bug in android-apt
Just a simple restart didn't work for me. I had to Invalidate Caches and Restart
then I could see the binding classes. It's under the File
menu for those who don't know.
<data class="MainActivityBinding">
<variable
name="user"
type="com.example.administrator.my_mvvm.User" />
</data>
//Remember need Build-> Rebuild Project
check the fields access level of your object, when i turned public it worked here