Android View Inflate例外

时间:2014-11-22 07:12:40

标签: android xml android-layout

在我的项目中,我使用名为PigeonSketch的活动,每当我打开活动时,它都会android.view.InflateException: Binary XML file line #15: Error inflating class <unknown>

这是我的Activity类和XML布局文件

public class PigeonSketch extends Activity {

    private RelativeLayout dashBoard;
    private ImageView imagePigeon;
    private Button search;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.pigeon_sketch);
        setTitle("Pigeon")

        dashBoard = (RelativeLayout) findViewById(R.id.pigeon_dashBoard);
        imagePigeon = (ImageView) findViewById(R.id.pigeonsketch);
        search = (Button) findViewById(R.id.searchButton)
    }

布局:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".GridViewList" >

    <RelativeLayout
        android:id="@+id/pigeon_dashBoard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp" >

        <ImageView
            android:id="@+id/pigeonsketch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/app_name"
            android:src="@drawable/image_pigeon"
            android:visibility="invisible" />
    </RelativeLayout>

    <Button
        android:id="@+id/searchButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Search" />

</RelativeLayout>

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

尝试改变

tools:context=".GridViewList"

到这个

tools:context=".PigeonSketch"

或删除该行..

答案 1 :(得分:0)

首先,您使用的是错误的工具参考:

tools:context=".PigeonSketch"

其次你在xml中定义Button并使用ImageButton查找,所以用Activity中的Button替换ImageButton:

private Button search;

search = (Button) findViewById(R.id.searchButton)