Layout activity_main.xml :
<layout> <android.support.v4.widget.DrawerLayout 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" android:fitsSystemWindows="true" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/layout_content" android:id="@+id/content" /> </LinearLayout> </android.support.v4.widget.DrawerLayout> </layout>
generates ActivityMainBinding.java . In your MainActivity.java, you use the generated field for content in the setSupportActionBar argument:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityMainBinding binding = DataBindingUtil.setContentView(this,R.layout.activity_main); setSupportActionBar(binding.content.toolbar); }
Typically, the layout will generate public end fields for each of the views with subclasses of android:id and Binding for each of the inclusions with identifiers. In this case, the data binding system did not detect that the included content @layout/layout_content was the binding layout and thus did not capture the Binding class for include.
When a variable is bound to include, the data binding system will use this to determine that the included layout is the binding layout. So, if your layout had this:
<include layout="@layout/layout_content" android:id="@+id/content" app:someVar="@{someVar}" />
You have received a field of type LayoutContentBinding . This assumes that someVar declared in both activity_main.xml and layout_content.xml .
An error in Android Studio indicated the correct location, but was difficult to understand. In the future, you can search for the generated binding class in your app/build directory. This may help you understand what the error means.
I registered an error to fix the error - we must create a public final field for include with identifier.
George mount
source share