令人费解的Android的xmlns错误

问题描述:

我已经在许多地图的例子遇到这样的代码:令人费解的Android的xmlns错误

<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" 
    tools:context=".MainActivity" > 

    <fragment 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" /> 

</RelativeLayout> 

然而,对于所有这些,它去,我得到错误

意外描述资源路径位置类型命名空间前缀 “的xmlns” 找到的标签 片段activity_msmap.xml /示例/ RES /布局线8的Android棉绒 问题

在行

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

所以......这到底是怎么回事?我在任何地方都可以看到它,但是在我的Eclipse/Android中导致错误?另外,为什么在父元素中定义时重复相同的xml名称空间?

您不能在xml布局中定义两次命名空间。 只需将它从片段中移除,RelativeLayout就已经定义了xmlns:android命名空间。

<fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" /> 
+0

感谢您的澄清:) – Tom 2013-03-09 10:25:29