Jump to content

Kotlin, Data binding error even already declared and imported

JoneLoveIT

I dont get why the below code have no error while above got an error (already declare "buildFeatures {dataBinding true}")

 

error

image.png.a779267b79b7f79b5511651f9db8e465.pngimage.png.99e6b23c8f00f863eb8053759e6de89b.png 

 

 

 

 

 

no error

image.png.f2442fa68f6f406fd6bf7e057d1d9090.pngimage.png.efa23c44a6f00e4cfcf60fc2d4d4600a.png

 

Link to comment
Share on other sites

Link to post
Share on other sites

Hard to tell from the small snippets you posted. It would also be better to post the code inside code tags, rather than screenshots. Makes it hard to copy and reference things.

 

The compiler can't seem to find the "databinding" package in the first screenshot, so I assume one of the following is true:

  • You haven't added dataBinding in the correct place in the build.gradle file
  • You haven't run a Gradle sync yet
  • The code hasn't been generated yet
  • The layout file isn't called activity_main.xml
  • You have an error in your layout file

 

Remove the import, sync Gradle then rebuild your project and try to import it again.

 

~edit: I just noticed that your top level element is "Layout", which makes no sense. If you mouse over the yellow highlight Android Studio should tell you that this element isn't allowed there. If you fix your layout it should probably fix your view binding issues.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×