Can't resolve Android databinding class

前端 未结 23 2141
南旧
南旧 2020-12-02 19:55

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

相关标签:
23条回答
  • 2020-12-02 20:15

    In my case: Solve problem without renaming XML file.

    I checked all case and I did everything like Invalidate Caches/Restart Android Studio, clean Project, Rebuild Project but But the error is not resolved.

    Solution - Just I change some code and revert that code again in activity XML file or change code in XML file.

    Note - This is very late answer but may be help others who don't want change XML file name. :)

    0 讨论(0)
  • Please put this code in build.gradle(app level), if not declared.

    android {
        dataBinding.enabled true
        viewBinding {
            enabled = true
        }
    }
    

    // Android Studio 4.0

    android {
        dataBinding.enabled true
        buildFeatures {
            viewBinding = true
        }
    }
    
    0 讨论(0)
  • 2020-12-02 20:17

    Make sure your activity_main.xml file is enclosed with layout tags like so:

    <?xml version="1.0" encoding="utf-8"?>
    <layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools">
    
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
        </android.support.constraint.ConstraintLayout>
    </layout>
    
    0 讨论(0)
  • 2020-12-02 20:19

    TRY Renaming the xml file to another name and check if binding works once it works rename it back to the one that was used.

    That helped for Android Studio 3.1

    0 讨论(0)
  • 2020-12-02 20:19

    I recently installed android studio 3.5.3 and this issue rised so what i did is.

    1) Clean Project
    2) Update Gradle (as notification was coming) 
    3) Rebuild project
    

    hope this helps.

    0 讨论(0)
  • 2020-12-02 20:20

    Cant comment so i'll just add this in answer. I believe activity_main.xml will create ActivityMainBinding rather than MainActivityBinding as you mentioned. in some cases where studio can't find the binding class then just invalidate the caches and rebuild the project.

    0 讨论(0)
提交回复
热议问题