Dalibor Frivaldsky
Dalibor Frivaldsky

Reputation: 850

android include tag - invalid layout reference

I'm having a problem including a different layout through the include tag in the android layout xml file. When specifing the layout reference ( @layout/... ), i'm getting a InflateException in the Eclipse ADT with the following error: InflateException: You must specifiy a valid layout reference. The layout ID @layout/func_edit_simple_calculator_toolbox is not valid.

the reference should be valid, as I've selected it from the the list of my other layouts and didnt type it in. I'm using android sdk v2.1

these are the layout files

func_edit_simple_calculator_toolbox.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="wrap_content" android:layout_width="wrap_content">

<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"android:layout_height="wrap_content">
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2"></Button>
<Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3"></Button>
<Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+"></Button>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="@+id/Button05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4"></Button>
<Button android:id="@+id/Button06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5"></Button>
<Button android:id="@+id/Button07" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6"></Button>
<Button android:id="@+id/Button08" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-"></Button>
</TableRow>
</TableLayout>

function_editor_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<com.calculoid.FunctionView android:id="@+id/function_view" android:layout_width="fill_parent" android:layout_height="fill_parent"/>

<include android:id="@+id/include01" android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/func_edit_simple_calculator_toolbox"></include>
</LinearLayout>

Does any one know what could be the problem?

thanks in advance

Upvotes: 43

Views: 30226

Answers (8)

Lorenzo Barbagli
Lorenzo Barbagli

Reputation: 1281

For me the problem was that the name of the layout was wrong: I used "-" instead of "_". AndroidStudio didn't tell me somthing was wrong till I tried to deploy the app

Upvotes: 0

cottonBallPaws
cottonBallPaws

Reputation: 21600

If anyone stumbles upon this thread looking for this error:

Caused by: android.view.InflateException: You must specifiy a layout in the include tag: <include layout="@layout/layoutID" />

Make sure you do:

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

and not:

<include android:layout="@layout/your_layout" />

layout should not have android: in front of it.

Upvotes: 116

Victor Chelaru
Victor Chelaru

Reputation: 4807

For those using Xamarin Studio - I added a bunch of AXML files from a different project, and also was getting the exact same error. I simply shut down and restarted Xamarin Studio (PC) and this also solved the problem. It's interesting that a different IDE has the same issue.

Upvotes: 0

dwbrito
dwbrito

Reputation: 5254

Check for empty

<include>
</include>

tags, (probably caused by automatic code formatting).

They can appear somewhere 'hidden' in your xml.

Upvotes: 0

mrBorna
mrBorna

Reputation: 1777

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

Upvotes: 0

ggomeze
ggomeze

Reputation: 5741

I think i should mention how i solved the same problem. Tried cleaning the project and didn't work. I have quite large names for the layout (chrono_first_small_field), and that wasn't the cause either.

Closed Eclipse, and just opened it again, and that worked.

That makes more sense than having to implement the onMeasure method :-)

Upvotes: 106

Dalibor Frivaldsky
Dalibor Frivaldsky

Reputation: 850

I've "solved" the problem, but I dont know what really helped. My layout files did not went through any major rewrite and practically contain the same. The only notable change I've done before the problem went away was to override the onMeasure( int, int ) method in my custom view class, with the implementation just calling setMeasuredDimension( 100, 100 ).

Upvotes: 0

Steve Haley
Steve Haley

Reputation: 55714

I don't see anything immediately wrong with that, so that's a bit odd. I can only think of two things: 1) Have you tried using a shorter file name? There are a few restrictions on what's acceptable in a file name, e.g. no uppercase characters or symbols, in order to ensure compatibility and file name length might be one of them. 2) Have you tried removing some of your android:... statements in the include, and leaving it at just <include layout="@layout/..."/>? You don't actually need to specify its height and width in the include as that's already defined in the imported layout file.

Upvotes: 1

Related Questions