Android找不到xml项

Android找不到xml项,android,xml,Android,Xml,我正在创建一个带有按钮的android应用程序,我的xml如下所示: <Button android:id="@+id/start" android:text="Start" android:layout_width="match_parent" android:layout_height="wrap_content" /> 但是,当我执行此操作时,应用程序将不会运行,因为这一行有错误: start = findViewById(R.id.start

我正在创建一个带有按钮的android应用程序,我的xml如下所示:

<Button
    android:id="@+id/start"
    android:text="Start"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
但是,当我执行此操作时,应用程序将不会运行,因为这一行有错误:

start = findViewById(R.id.start);

但我很肯定地找到了按钮。有人能解释为什么这不起作用吗?

方法
findViewById()
返回一个
视图。您需要将其转换为
按钮

start = (Button) findViewById(R.id.start);

欢迎来到SO!你的问题写得很好,所以+1。但如果将来适用,请将错误/异常/logcat输出包含在您的帖子中。我相信您现在已经从@ThalluimPig获得了答案,但您仍然可以在帖子中添加错误消息,以帮助将来的用户解决同样的问题。感谢您添加解释,而不仅仅是代码。整个社区都理解+1:)
start = (Button) findViewById(R.id.start);