2013-09-05 35 views
1

我正在開發基於gmap的應用程序。應用程序不接受xml文件中的gmap

爲此,我正在關注this文件。

它給我的錯誤就mainactivity.xml爲下面的代碼:

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

<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" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    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" 
      android:name="com.google.android.gms.maps.MapFragment"/> 

</RelativeLayout> 

錯誤行:

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

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

錯誤文本:

Description Resource Path Location Type 
Unexpected namespace prefix "xmlns" found for tag fragment activity_main.xml /gmapAPP/res/layout line 14 Android Lint Problem 
The processing instruction target matching "[xX][mM][lL]" is not allowed. activity_main.xml /gmapAPP/res/layout line 1 Android XML Format Problem 

我的清單文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.gmapapp" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 


    <uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <uses-library android:name="com.google.android.maps"/> 

     <activity 
      android:name="com.example.gmapapp.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="your_apikey" /> 

    </application> 

</manifest> 

請幫助我。

回答

1

試試這個SupportMapFragment而不是最後一行中的MapFragment,也看看你的片段標籤。

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

<RelativeLayout 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 


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

</RelativeLayout> 

轉寄此Example

1

從片段類在XML中刪除:

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

不知道我在這裏幫助,但我只在我的情況下,一旦申報命名空間中

<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" > 

    <fragment class="com.blablabla.MyFragment" 
     android:id="@+id/fragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</RelativeLayout> 
+0

仍然錯誤是存在於行:<片段的xmlns:機器人= 「http://schemas.android.com/apk/res/android」 –

+0

說明\t資源\t路徑\t位置\t類型 意外的命名空間前綴 「的xmlns」 找到的標籤斷\t activity_main.xml中\t/gmapAPP/RES /佈局\t線14 \t的Android林特問題 –

1
<?xml version="1.0" encoding="utf-8"?> 
<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" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 


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

</RelativeLayout> 
相關問題