관련 내용을 검색해보면, 주로 Clean & Rebuild 또는 Invalidate Caches / Restart 같은 메뉴를 실행해라는 글이 많다.
이 옵션들은 "나는 제대로 다 했는데, 안스가 문제야" 일 때 사용하는 옵션들이다.
하지만 나의 경우, 이 에러는 주로 데이터바인딩에서 잘못된 문법을 사용해서 나타난 문제였다.
Databinding
의 Syntax error 같은 느낌이랄까...
아무튼 문제 코드는 RecyclerView
의 Adapter
를 가져오는 부분이 문제였다.
...
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/customRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:verAdapter="@{viewmodel::getAdapter}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
...
getAdapter()
를 하면 내가 생성한 RecyclerView
의 객체를 가져올 수 있는데, 여기서 ::
더블 콜론을 사용한 것이 문제였다.
이중 콜론 연산자는 메소드 참조 표현식(Method Reference Expression)라고 하는데, 말 그대로 람다 표현식에서만 사용 가능하다.
따라서 람다 표현식이 아닌 getAdapter
와 같은 일반 함수는 저렇게 쓰면 안 된다.
🛠 해결
...
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/customRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:verAdapter="@{viewmodel.getAdapter()}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
...
@{viewmodel::getAdapter}
를 @{viewmodel.getAdapter()}
로 변경하면 해결된다.
이 에러가 단순히 오래되거나 잘못된 캐시가 있어서 나는 오류만이 아니라는 것을 알리기 위해 포스팅한다.
근데 나 같은 실수는 아무도 하지 않을 것 같음.