tosh17
tosh17

Reputation: 192

Problem with DataBinding - Error cannot find symbol

I have a problem with DataBindig, I am trying to run this in Fragment

FragmentUserProfileEditMain:

class FragmentUserProfileEditMain : Fragment(), ViewStateUserProfileEditMain {
   lateinit var binding: FragmentUserProfileEditMainBinding
   override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
        }

        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
             binding = DataBindingUtil.inflate(
                inflater, R.layout.fragment_user_profile_edit_main, container, false)
            return binding.getRoot()
        }

Gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    dataBinding {
        enabled = true
    }
   .....
}
dependencies {
    def dagger_version = "2.18"
    def support_version = '1.0.0-beta01'
    def arch_version = '2.0.0-alpha1'
    ...
    //Google Arch
    implementation "androidx.lifecycle:lifecycle-extensions:$arch_version"
    kapt "androidx.lifecycle:lifecycle-compiler:$arch_version"
    implementation "androidx.room:room-runtime:$arch_version"
    kapt "androidx.room:room-compiler:$arch_version"
    kapt "androidx.databinding:databinding-compiler:3.3.2"

    implementation 'android.arch.navigation:navigation-fragment:1.0.0-rc02'
    ......
    }

fragment_user_profile_edit_main.xml:

<?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">
    <data>
        ...
    </data>
    <ScrollView

            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
                                                           android:layout_height="wrap_content">
    ...

class FragmentUserProfileEditMainBinding was generated, but compiler show error:

D:\Android\cod\app\build\generated\source\kapt\debug\ru\test\data\DataBinderMapperImpl.java:18: error: cannot find symbol
import ru.ohmypeer.peers.databinding.FragmentUserProfileEditMainBindingImpl;
                                    ^
  symbol:   class FragmentUserProfileEditMainBindingImpl
  location: package ru.test.data.databinding

I try to open, close Android studio. Clear/rebuild project, Invalidate cache/restart

Upvotes: 0

Views: 9009

Answers (4)

Rishabh mishra
Rishabh mishra

Reputation: 11

I was faced the same thing, almost waste my One and a half days for this. Finally i found issue in this line.

I was using OnClick function like this:

android:onClick="@{()->modelData.onSubmitLogin()}"

instead of this:

android:onClick="@{() -> modelData.onSubmitLogin()}"

Remember space before and after lambda operator.

Upvotes: 0

burak isik
burak isik

Reputation: 581

This problem may be caused by layout file. In my case I just use wrong variable name.

  <data>
        <variable
            name="theme"
            type="...model.RealmTheme" />
    </data>

android:text="@{word.name}"

instead of

android:text="@{theme.name}"

Upvotes: 0

krm266
krm266

Reputation: 61

Just incase anyone else has this problem and finds this page in a search. The issue for me was that I copied a layout from another view and forgot to remove the reference to the other view's viewmodel.

Upvotes: 0

tosh17
tosh17

Reputation: 192

it is was my fault I try set layout_height from data

Upvotes: 1

Related Questions