Android Google Maps fragment in the xml. I get “Un

2019-01-17 05:55发布

I'm trying to learn android, and having followed the instructions on how to use the Google Maps API V.2 I now got it working. However, the instructions on how to configure the initial state of the maps, found at developers.google.com, suggests a namespace defined in the xml-file, in this case "map".

The xml-code below gives med the error "Unexpected namespace prefix "map"". Trying to define the xmlns:map inside the fragment tag gave the same error but with "xmlns".

I'm obviously missing some fundamental xml-knowledge here, can someone help me out?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"        
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"      <!-- Definition -->
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

</RelativeLayout>

9条回答
放荡不羁爱自由
2楼-- · 2019-01-17 06:45

I have the same problem today. I upgraded the SDK last night and did not see this problem before. I had the Android Map V2 sample demo project loaded too and today the "multimap_demo.xml" file is showing the "Unexpected namespace prefix "map" found for tag fragment" error. I applied the xml include suggested and it is working again. Would give it a +1 but got no cred.

UPDATE: I forgot about this problem and reworked my code today and removed the include. Of course the error came back. I found this and added it to the layout in the fragment stanza:

tools:ignore="MissingPrefix"

It seems to at least mask the problem.

Update: This bug apparently happens due to a bug in Android Lint Tool. Refer issue https://code.google.com/p/gmaps-api-issues/issues/detail?id=5002

查看更多
甜甜的少女心
3楼-- · 2019-01-17 06:52

In my case a big miss, I forget to add in the gradle file my google map dependency:

compile 'com.google.android.gms:play-services-maps:11.2.0'
查看更多
在下西门庆
4楼-- · 2019-01-17 06:53

I had this problem as well. I did Project/Clean and the error went away and it works fine now.

查看更多
登录 后发表回答