android: data binding error: cannot find symbol class

后端 未结 26 2841
生来不讨喜
生来不讨喜 2020-12-14 05:49

I am getting started for using DataBinding feature. I am facing problem with it.

Error:(21, 9) error: cannot find symbol class ContactL

相关标签:
26条回答
  • 2020-12-14 05:51

    Don't forget to add in app level gradle, apply plugin: 'kotlin-kapt'

    0 讨论(0)
  • 2020-12-14 05:51

    I have got the same issue and I found that variable name and method were missing. Double check the layout file or look for build error that says DATABINDINGISSUE, or invalidate and restart android studio. It should work.

    0 讨论(0)
  • 2020-12-14 05:51

    You need to add the tags into your Activity's Xml Layout.

    <?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">
        <data>
            <variable
                 name=""
                 type="" />
        </data
        <android.support.design.widget.CoordinatorLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
      tools:context="com.letsnurture.ln_202.databindingdemo.ContactListActivity">
    
        </android.support.design.widget.CoordinatorLayout>
    </layout>
    

    and then, add an android:id into your tag

    After that, you'll have a ActivityContactListBinding object and you can access and bind variables on your included layouts.

    0 讨论(0)
  • 2020-12-14 05:52

    your model just have getter and setter in androidX. else not find your model in view and show this bug

    public class User {
    
    String name;
    
    public String getName() {
        return name;
    }
    public User(String name) {
        this.name = name;
    }
    

    }

    0 讨论(0)
  • 2020-12-14 05:54

    I was calling my onClick wrong, which caused this error. So I changed

    android:onClick="@{listener.onDogClicked()}"
    

    to

    android:onClick="@{listener::onDogClicked}"
    
    0 讨论(0)
  • 2020-12-14 05:54

    In my case I had the same issue but the reason was different. My onClick function was declared private in the activity class, so be sure that, if you are using a handler function inside the layout, the function must not be private.

    // this will not be visible in the binded layout because it's private!
    private fun mainButtonClick(view: View) {
        if (viewModel.isRecording.value == true) {
            stopRecordingAndPlaying()
        } else {
            startRecordingAndPlaying()
        }
    }
    
    0 讨论(0)
提交回复
热议问题