Android studio 必须声明元素LinearLayout

Android studio 必须声明元素LinearLayout,android-studio,android-linearlayout,Android Studio,Android Linearlayout,我已经更新了android studio,现在我的main.xml出现问题,它显示以下错误: 必须声明元素线性布局 这是我的代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="

我已经更新了android studio,现在我的main.xml出现问题,它显示以下错误:
必须声明元素线性布局

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:gravity="center_vertical|center_horizontal"
    >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/monBouton"
        android:text="Cliquez ici !"
        >
    </Button>
</LinearLayout>

这是错误消息:

错误:任务“:app:compiledBugJava”的执行失败。 编译失败;有关详细信息,请参阅编译器错误输出

错误:找不到符号变量操作设置


如何解决此问题?

请确保在菜单的xml文件中定义了
操作设置

res/menu/yourmenufile.xml
像这样:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.app" >

    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />
</menu>


有相同的错误。问题是,我的dialogfragment布局在菜单文件夹中,而不是布局文件夹中

您的布局文件必须在
res/layout
文件夹中


包含完整的错误消息。包含完整的错误消息,谢谢。我也有相同的错误,原因是我将xml文件放在
drawable/
目录中,而不是
layout/
目录中。这解决了我的问题。通常这是一般情况下的答案。