본문 바로가기

Android/err

databinding error impl 관련

간단한 실수인데 찾으려하니 자료가 보이지 않아 작성합니다..
(제 생각을 토대로 원인과 방법을 설명 했습니다. 혹시나 틀린 부분이 있다면 알려주세요)
스터디 겸 간단한 프로젝트 진행 중에 빌드를 하다보니 databinding 쪽에서 계속 에러가 발생 ㅠ

ActivityBindingImpl  error: cannot find symbol
등과 같은 에러가 계속 발생하여 clean Build도 해보고 cash문제 인건가 해서 Invalidate Caches도 해보고
여러 차례 시도 해보았습니다

제가 생각한 원인은

<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="viewmodel"
                type="kr.hoony.mvvmtoy.view.mainlist.MainListViewModel" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 tools:context=".view.mainlist.MainListFragment">
        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                tools:listitem="@layout/list_item">
        </androidx.recyclerview.widget.RecyclerView>
        <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:src="@drawable/ic_add_black_24dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:id="@+id/btn_add"
                android:onClick="@{()->viewmodel.goToCreate()}"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_marginBottom="16dp"
                android:layout_marginRight="16dp"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>
class MainListViewModel(

) : BaseViewModel() {

    fun goToCreate(view: View) {
        Navigation.findNavController(view).navigate(R.id.action_mainListFragment_to_createFragment)
    }
}

가져온 variable에서 저 함수가 없어서 에러가 발생 하는걸로...

함수 뿐만 아니라 변수에서도 같은 에러가 발생하는걸로 보여집니다

(혹시나 Impl가 없다는 에러가 발생하게 된다면 xml에서 혹시 오타를 찾아보시는것도...)



그냥 단순히 다른 예제 보면서 복사 붙여넣기 했다가.... 함수에 파라미터를 전달을 안해서 에러가 발생한 것으로...

 

저 빨간 부분을 그래서

android:onClick="@{(view)->viewmodel.goToCreate(view)}" 

로 변경해서 처리 혹은

android:onClick="@{viewmodel::goToCreate}"

하니 아주 잘 동작하네여..

 

저와 같이 혹시나 문제가 생기시는 분들이 있을까 싶어 이렇게 남깁니다~