500865
500865

Reputation: 7120

Android - <include layout=.../> returns error

I have a library project in which I define an action bar in layout file action_bar.xml like this :

   <?xml version="1.0" encoding="utf-8"?>
   <merge xmlns:android="http://schemas.android.com/apk/res/android">
       <LinearLayout style="@style/actionBar" />
    </merge>

The corresponding style element is this :

<style name="actionBar">
    <item name="android:id">@id/action_bar_container</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">@dimen/title_height</item>
    <item name="android:orientation">horizontal</item>
    <item name="android:background">@drawable/action_bar_background</item>
</style>

When I try to include the action bar in another layout file dashboard_activity_layout.xml like below :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/CustomTheme"
    android:id="@+id/activity_dashboard_root_container" 
    android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <include layout="@layout/action_bar"/>

    <LinearLayout android:orientation="vertical"
            android:id="@+id/fragment_container"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="1" 
        android:padding="6dip">
    </LinearLayout>

</LinearLayout>

It is continuously throwing the error :

You must specifiy a valid layout reference. The layout ID @layout/action_bar is not valid. Exception details are logged in Window > Show View > Error Log

I think this is a very simple problem and I'm missing a small detail. Any help is appreciated. I have adapted this from the Google I/O code. Does it have to do with the Library Project?

Upvotes: 4

Views: 2961

Answers (4)

mrBorna
mrBorna

Reputation: 1777

launch eclipse with the -clean option and your problem is fixed. It will take about 30 seconds longer to launch though

Upvotes: 0

Jeff Axelrod
Jeff Axelrod

Reputation: 28188

This appears to be a documented ADT bug here and here and still exists in ADT R16.

Upvotes: 2

500865
500865

Reputation: 7120

Even though eclipse gave me this error. I was able to run the app which was using the library project and the behaviour seen was the expected one. I think this is something to do with eclipse.

Upvotes: 2

Vinay
Vinay

Reputation: 2415

@Promod, You have opened a Linear layout in Action_bar.xml. But you have not added any items inside the linear layout.

  1. Linear layout needs minimum parameters like, layout_width, layout_height. Try adding them.

Upvotes: 0

Related Questions