18

我正在创建一个使用 res 文件夹中的 menu.xml 文件的 android 应用程序。但我收到了上述错误。这是什么意思?我该如何解决?

菜单.xml:

<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item id="@+id/my_location"
android:icon="@drawable/my_location"
android:title:="Current location" />

<item id="@+id/mapview_satellite"
android:icon="@drawable/satelliteview"
android:title="Satellite View" />

<item id="@+id/mapview_normal"
android:icon="@drawable/normalview"
android:title="Normal view" />
</menu>
4

9 回答 9

30

更改<item id="@+id/my_location"<item android:id="@+id/my_location"。这在所有三个地方。

另外,在这里:android:title:="Current location"删除title.

于 2013-01-05T12:00:51.917 回答
11

您还需要确保以下两行在您的属性列表中:

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

如果您忽略这些,Eclipse 只会给您“缺少 android 前缀”错误。

于 2013-12-25T17:34:02.853 回答
5

信不信由你,对于任何试图通过下载书籍中的示例来工作的人,您可能需要确保您有真正的引号,因为编译器可以理解它们。当我尝试以小方式修改 XML 文件时,我遇到了与 OP 相同的错误,以及许多类似的解析错误。然后我注意到粘贴的代码片段中的引号与我键盘上的引号不同(在片段中它们向右倾斜,如果我自己输入它们,它们是直上直下的)。

我知道这听起来很疯狂,我自己都不敢相信,但是当我重新输入我的报价时,它工作得很好。

于 2013-06-28T05:01:42.733 回答
2

添加android:在属性解决我的问题之前。

于 2013-05-14T01:34:11.117 回答
1

有时 XML 代码可能编写正确,因此您需要简单地剪切当前拥有的内容,然后将其从行号中删除,然后重新粘贴,错误应该会得到修复。如果没有,那么您就知道您的代码是错误的。xml 默认是识别您首先放置的内容,需要删除才能重新开始。相信我,我刚刚在那个问题上花了 3 天时间,并且完全按照上面所说的做了,祝你好运。

于 2013-03-22T02:49:56.740 回答
1

在项目目录中创建一个 XML 文件res/menu/不在res文件夹 &

不要忘记为 id 属性添加前缀。

试试这样

<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/my_location"
        android:icon="@drawable/my_location"
        android:title="Current location" />

    <item android:id="@+id/mapview_satellite"
        android:icon="@drawable/satelliteview"
        android:title="Satellite View" />

    <item android:id="@+id/mapview_normal"
        android:icon="@drawable/normalview"
        android:title="Normal view" />
</menu>
于 2013-01-05T12:01:52.090 回答
1

如果你有这样的事情:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
   <data>
        <variable  name="person" type="com.abc.PersonEntity"/>
    </data>

将数据移动到布局标签内:

<layout xmlns:android="http://schemas.android.com/apk/res/android"  >
       <data>
          <variable  name="person" type="com.abc.PersonEntity"/>
       </data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> 
...
于 2018-01-12T20:07:32.123 回答
0

您忘记为id属性添加前缀。尝试这样做:

<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/my_location"
        android:icon="@drawable/my_location"
        android:title="Current location" />

    <item android:id="@+id/mapview_satellite"
        android:icon="@drawable/satelliteview"
        android:title="Satellite View" />

    <item android:id="@+id/mapview_normal"
        android:icon="@drawable/normalview"
        android:title="Normal view" />
</menu>
于 2013-01-05T12:03:05.910 回答
0

有两个错误愚蠢的错误

- id isn't it attribute is android:id
- First itme android:title:= you have written extra colon after title

这是实现的代码

<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/my_location"
        android:icon="@drawable/my_location"
        android:title="Current location"/>
    <item
        android:id="@+id/mapview_satellite"
        android:icon="@drawable/satelliteview"
        android:title="Satellite View"/>
    <item
        android:id="@+id/mapview_normal"
        android:icon="@drawable/normalview"
        android:title="Normal view"/>

</menu>
于 2013-01-05T12:03:46.053 回答