必须声明Element LinearLayout

问题描述 投票:8回答:3

我已经更新了android studio,现在在main.xml中出现问题,它显示以下错误:element LinearLayout must be declared

这是我的代码:

<?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:compileDebugJava'的执行失败。编译失败;有关详细信息,请参见编译器错误输出。

错误:找不到符号变量action_settings

我该如何解决?

android-studio android-linearlayout
3个回答
4
投票

确保在菜单的xml文件中定义了action_settings

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>

19
投票

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

Providing Resources


4
投票

具有相同的错误。问题是,我的对话框片段布局位于菜单文件夹而不是布局文件夹中

© www.soinside.com 2019 - 2024. All rights reserved.