Master Mind
Master Mind

Reputation: 2406

android:<include> tag cause error

When i include a nav bar code xml in my another xml, it generates following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my/com.my.Login}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>

login.xml is

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

    <include
        android:layout_height="wrap_content"
        layout="@layout/navbar" />

</LinearLayout>

navbar.xml is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@style/tableRowStyle"
    android:orientation="horizontal"
    android:paddingRight="0dp" >

    <Button
        android:id="@+id/button2"
        android:layout_width="52dp"
        android:layout_height="48dp"
        android:background="@drawable/home" />

    <View
        android:layout_width="1px"
        android:layout_height="fill_parent"
        android:background="#1f1f1f" />

    <View
        android:layout_width="1px"
        android:layout_height="fill_parent"
        android:background="#454545" />

    <Button
        android:id="@+id/button1"
        android:layout_width="190dp"
        android:layout_height="48dp"
        android:layout_weight="0.35"
        android:background="@drawable/stock" />

    <View
        android:layout_width="1px"
        android:layout_height="fill_parent"
        android:background="#1f1f1f" />

    <View
        android:layout_width="1px"
        android:layout_height="fill_parent"
        android:background="#454545" />

    <Button
        android:id="@+id/button2"
        android:layout_width="52dp"
        android:layout_height="48dp"
        android:background="@drawable/home" />

</LinearLayout>

What's the problem behind it?

Upvotes: 2

Views: 469

Answers (4)

malavika
malavika

Reputation: 1331

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my/com.my.Login}: android.view.InflateException: Binary XML file line #1: Error inflating class

If you got this error means mismatch call of layout in your setContentView(R.id.xml_file); So first check and make sure if your calling the layout id correctly in your java code.

And just remove style="@style/tableStyle" in your xml . I think it will works.

Upvotes: 1

Master Mind
Master Mind

Reputation: 2406

removed android:background="@style/tableRowStyle"

now its working fine. Thank you all for your valuable answers :)

Upvotes: 0

adarsh
adarsh

Reputation: 6978

Could it be that

<include
    android:layout_height="wrap_content"
    layout="@layout/navbar" />

should be

<include
    android:layout_height="wrap_content"
    android:layout="@layout/navbar" />

Upvotes: 1

Misha Bhardwaj
Misha Bhardwaj

Reputation: 1387

Specify layout width also.

<include
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    layout="@layout/navbar" />

Upvotes: 0

Related Questions