Android的谷歌地图错误android.view.InflateException:二进制XML文件,6号线:错误启动类片段 [英] Android Google Map error android.view.InflateException: Binary XML file line #6: error initiating class fragment

查看:164
本文介绍了Android的谷歌地图错误android.view.InflateException:二进制XML文件,6号线:错误启动类片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,通过约15不同的堆栈溢出的问题上同样的错误会后,我对未能另一个问题开始活动ComponentInfo。

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.hauntingongrounds
    安卓版code =1
    机器人:=的versionName1.0>
    <许可
        机器人:名字=com.example.hauntingongrounds.permission.MAPS_RECEIVE
        安卓的ProtectionLevel =签名/>
    <使用许可权的android:NAME =com.example.hauntingongrounds.permission.MAPS_RECEIVE/>    <用途-SDK
        安卓的minSdkVersion =12
        机器人:targetSdkVersion =18/>    <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>    <! - 必须出示当前位置 - >
    <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>    <用途特征
    机器人:glEsVersion =0x00020000
    机器人:要求=真/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=com.example.hauntingongrounds.MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        &所述;元数据
            机器人:名字=com.google.android.gms.version
            机器人:值=AIzaSyAI ********** - EhL8Ys/>
    < /用途>< /清单>

以上是清单。下面是XML和主要活动。

 进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.MapFragment;
进口com.google.android.gms.maps.SupportMapFragment;进口android.app.Activity;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.support.v4.app.FragmentActivity;
进口android.widget.Toast;公共类MainActivity扩展FragmentActivity {    // 谷歌地图
    私人GoogleMap的GoogleMap的;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        尝试{
            //载入地图
            initializeMap();        }赶上(例外五){
            e.printStackTrace();
        }    }    / **
     *函数来加载地图。如果地图不创建它会为您创建它
     * * /
    私人无效initializeMap(){
        如果(GoogleMap的== NULL){
            使用GoogleMap =((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap();
            //检查是否映射成功与否创建
            如果(GoogleMap的== NULL){
                Toast.makeText(getApplicationContext(),
                        对不起!无法创建地图,Toast.LENGTH_SHORT)
                        。显示();
            }
        }
    }    @覆盖
    保护无效onResume(){
        super.onResume();
        initializeMap();
    }}

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.SupportMapFragment
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent/>< / RelativeLayout的>

最后LogCat中

  14 11-24:30:44.293:E / AndroidRuntime(17980):致命异常:主要
11-24 14:30:44.293:E / AndroidRuntime(17980):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.hauntingongrounds / com.example.hauntingongrounds.MainActivity}:android.view.InflateException:二进制XML文件6号线:错误充气类片段
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.os.Handler.dispatchMessage(Handler.java:99)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.os.Looper.loop(Looper.java:137)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.ActivityThread.main(ActivityThread.java:5041)
11-24 14:30:44.293:E / AndroidRuntime(17980):在java.lang.reflect.Method.invokeNative(本机方法)
11-24 14:30:44.293:E / AndroidRuntime(17980):在java.lang.reflect.Method.invoke(Method.java:511)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-24 14:30:44.293:E / AndroidRuntime(17980):在dalvik.system.NativeStart.main(本机方法)
11-24 14:30:44.293:E / AndroidRuntime(17980):android.view.InflateException:二进制XML文件,6号线:错误充气类片段产生的原因
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.Activity.setContentView(Activity.java:1881)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.example.hauntingongrounds.MainActivity.onCreate(MainActivity.java:21)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.Activity.performCreate(Activity.java:5104)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-24 14:30:44.293:E / AndroidRuntime(17980):... 11个
11-24 14:30:44.293:E / AndroidRuntime(17980):java.lang.IllegalStateException:在应用的Andr​​oidManifest.xml中的元数据标签没有正确的价值所致。预计4030500但发现0您必须在&lt中的以下声明;用途>元素:其中,元数据机器人:名字=com.google.android.gms.version机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.common.GooglePlayServicesUtil.n(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.maps.internal.q.v(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.maps.internal.q.u(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.maps.MapsInitializer.initialize(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.maps.SupportMapFragment $ b.cE(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.maps.SupportMapFragment $ b.a(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.dynamic.a.a(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.dynamic.a.onInflate(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在com.google.android.gms.maps.SupportMapFragment.onInflate(来源不明)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
11-24 14:30:44.293:E / AndroidRuntime(17980):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)


解决方案

  

产生的原因:java.lang.IllegalStateException:在应用的Andr​​oidManifest.xml中的元数据标签没有正确的价值。预计4030500但发现0。


您需要添加这对你的清单

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

So after going through about 15 different stack overflow questions on the same error, I have another question about the unable to start activity ComponentInfo.

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


    <permission
        android:name="com.example.hauntingongrounds.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.hauntingongrounds.permission.MAPS_RECEIVE" />

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="18" />

    <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" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

    <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="com.example.hauntingongrounds.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.gms.version"
            android:value="AIzaSyAI********************-EhL8Ys" />
    </application>

</manifest>

Above is the Manifest. Below are the XML and the Main Activity.

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {

    // Google Map
    private GoogleMap googleMap;

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

        try {
            // Loading map
            initializeMap();

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

    }

    /**
     * function to load map. If map is not created it will create it for you
     * */
    private void initializeMap() {
        if (googleMap == null) {
            googleMap = ((SupportMapFragment) getSupportFragmentManager().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();
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initializeMap();
    }

}

XML File

<?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.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

Finally the LogCat

11-24 14:30:44.293: E/AndroidRuntime(17980): FATAL EXCEPTION: main
11-24 14:30:44.293: E/AndroidRuntime(17980): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hauntingongrounds/com.example.hauntingongrounds.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.os.Looper.loop(Looper.java:137)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.ActivityThread.main(ActivityThread.java:5041)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at java.lang.reflect.Method.invokeNative(Native Method)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at java.lang.reflect.Method.invoke(Method.java:511)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at dalvik.system.NativeStart.main(Native Method)
11-24 14:30:44.293: E/AndroidRuntime(17980): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.Activity.setContentView(Activity.java:1881)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.example.hauntingongrounds.MainActivity.onCreate(MainActivity.java:21)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.Activity.performCreate(Activity.java:5104)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-24 14:30:44.293: E/AndroidRuntime(17980):    ... 11 more
11-24 14:30:44.293: E/AndroidRuntime(17980): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.maps.internal.q.v(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.maps.internal.q.u(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.dynamic.a.a(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
11-24 14:30:44.293: E/AndroidRuntime(17980):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)

解决方案

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0.

You need to add this on your manifest

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

这篇关于Android的谷歌地图错误android.view.InflateException:二进制XML文件,6号线:错误启动类片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆