Android/Error Log

[Android] <include> 태그 사용 시 오류

seunghwaan 2021. 4. 9. 12:19
반응형

상위 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"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include
                android:id="@+id/layout_toolbar"
                layout="@layout/tb_ranking" />

        </com.google.android.material.appbar.AppBarLayout>

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorBlack"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">



      ~~~ 생략 ~~~

하위 xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="랭킹"
        android:textColor="@color/colorWhite"
        android:textSize="33sp"
        android:textStyle="bold" />

</androidx.appcompat.widget.Toolbar>

오류 내용 

error: incompatible types: TbRankingBinding cannot be converted to ViewDataBinding setContainedBinding(this.layoutToolbar);

원인과 해결방법

해당 에러가 발생했던 이유는 너무나 간단하게도 상위 xml은 데이터바인딩 기반으로 xml을 구성하는데 하위 xml은 데이터바인딩을 인식하지 못해서 발생한 에러였다. 그래서 하위 xml도 데이터바인딩으로 묶어서 바로 해결!

반응형