Henok Getachew Henok Getachew - 3 months ago 33
Android Question

Android studio 2.1 databinding cannot resolve symbol

my project structure is as follows
i have added

dataBinding { enabled true }
to
build.gradle (module app)

i have added
classpath "com.android.databinding:dataBinder:1.0-rc4"
to
build.gradle(project)

my activity's layout is
activity_fullscreen.xml
so i tried to use
ActivityFullscreenBinding
and it brings "cannot resolve symbol" error. is there something i need to import. fyi i'm using android studio 2.1
i am already using gradle 2.1.0
Here is activity_fullscreen.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/white"
tools:context="com.roha.lungo.FullscreenActivity">

<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->

<RelativeLayout
android:background="@android:color/black"
android:layout_width="match_parent"
android:id="@+id/relativeLayout"
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="wrap_content"></android.support.v4.view.ViewPager>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:onClick="@{FabHandler::onBaseFabClick}"
android:src="@drawable/ic_mic_black_24dp" />

<LinearLayout
android:id="@+id/fab_menu_one_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="invisible"
android:layout_alignParentRight="true"
android:layout_above="@id/fab"
>

<TextView
android:id="@+id/shareLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/circle_background_red"
android:elevation="2dp"
android:fontFamily="sans-serif"
android:padding="5dip"
android:text="Share"
android:textColor="@android:color/white"
android:typeface="normal" />


<android.support.design.widget.FloatingActionButton
android:id="@+id/shareFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="@{FabHandler::onShareFabClick}"
android:tint="@android:color/white"
fabSize="mini"
srcCompat="@android:drawable/arrow_down_float"/>

</LinearLayout>

<LinearLayout
android:id="@+id/fab_menu_two_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="invisible"
android:layout_alignParentRight="true"
android:layout_above="@id/fab_menu_one_layout"
>

<TextView
android:id="@+id/createLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/circle_background_red"
android:elevation="2dp"
android:fontFamily="sans-serif"
android:padding="5dip"
android:text="Create"
android:textColor="@android:color/white"
android:typeface="normal" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/createFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="@{FabHandler::onCreateFabClick}"
android:tint="@android:color/white"
app:fabSize="mini"
app:srcCompat="@android:drawable/btn_star_big_on" />

</LinearLayout>


</RelativeLayout>

<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<RelativeLayout
android:id="@+id/fullscreen_content_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:orientation="horizontal"
tools:ignore="UselessParent">

</RelativeLayout>
</FrameLayout>
</FrameLayout>

Answer

The layout xml should be wrapped by layout tag.

Your activity_fullscreen.xml should be like this:

<layout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">

    <FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:background="@android:color/white"
                 tools:context="com.roha.lungo.FullscreenActivity">
    ...
    </FrameLayout>

</layout>

Then rebuild your project from AndroidStudio's menu:

Build -> RebuildProject.

There will be errors:

Error:(34, 40) Identifiers must have user defined types from the XML file. FabHandler is missing it

You can solve this problem by add data tag. Please refer this document. https://developer.android.com/topic/libraries/data-binding/index.html

Comments