谷歌地图v2的未加载。错误android.view.InflateException:二进制XML文件中的行..错误充气类片段错误、片段、加载、地图

2023-09-03 21:29:05 作者:是男人就像爷们一样活这

这是我的MainActivity。最低SDK版本是在我的应用程序11。我用Android清单文件中的API密钥。当我做了一些小的修改,它显示我的空白空间,而不是地图。

 公共类MainActivity延伸活动{

// 谷歌地图
私人GoogleMap的GoogleMap的;

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);

    尝试 {
        //载入地图
        initilizeMap();

    }赶上(例外五){
        e.printStackTrace();
    }

}

/ **
 *函数来加载地图。如果没有创建地图会为您创建
 * * /
私人无效initilizeMap(){
    如果(GoogleMap的== NULL){
        GoogleMap的=((MapFragment)getFragmentManager()。findFragmentById(
                R.id.map))的GetMap()。

        //如果映射成功与否创建检查
        如果(GoogleMap的== NULL){
            Toast.makeText(getApplicationContext(),
                    对不起!无法创建地图,Toast.LENGTH_SHORT)
                    。显示();
        }
    }
}


}
 

这是我的布局activity_main.xml

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>

<片段
    机器人:ID =@ + ID /图
    类=com.google.android.gms.maps.MapFragment
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:名称=com.prasad.maptrial.MainActivity/>

< / RelativeLayout的>
 
iOS版谷歌地图获得 停站 功能

这是我的Manifest.xml

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.prasad.maptrial
安卓版code =1
机器人:VERSIONNAME =1.0>

<用途-SDK
    安卓的minSdkVersion =11
    机器人:targetSdkVersion =23/>

<使用-权限的Andr​​oid:名称=android.permission.ACCESS_NETWORK_STATE/>
<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<使用-权限的Andr​​oid:名称=com.google.android.providers.gsf.permission.READ_GSERVICES/>

<! - 必须出示当前位置 - >
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_COARSE_LOCATION/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_FINE_LOCATION/>
<使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/>

<! - 必需的OpenGL ES 2.0。对于地图V2  - >
<用途特征
    机器人:glEsVersion =0x00020000
    机器人:要求=真/>

<应用
    机器人:allowBackup =真
    机器人:图标=@可绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <活动
        机器人:名称=。MainActivity
        机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>

            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
    &所述;元数据
        机器人:名称=com.google.android.maps.v2.API_KEY
        机器人:值=(我的API密钥)/>
< /用途>

< /舱单>
 

解决方案

提及这个元数据标记

 <元数据
        机器人:名称=com.google.android.gms.version
        机器人:值=@整数/ google_play_services_version/>
 

删除开放GLS谭andand让我知道结果

This is my MainActivity. minimum sdk version is 11 in my app. I used the API key in the android manifest file. When I did some minor modifications, it is showing me blank white space instead of map.

public class MainActivity extends Activity {

// Google Map
private GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
        // Loading map
        initilizeMap();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

/**
 * function to load map. If map is not created it will create it for you
 * */
private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}


}

This is my layout activity_main.xml

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

<fragment
    android:id="@+id/map"
    class="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.prasad.maptrial.MainActivity"/>

</RelativeLayout>

This is my Manifest.xml

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".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="(MY API KEY)" />   
</application>

</manifest>

解决方案

mention this meta data tag

  <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

remove open gls tan andand let me know the result