加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Android谷歌地图错误android.view.InflateException:二

发布时间:2020-12-15 04:15:42 所属栏目:Java 来源:网络整理
导读:因此,在对同一错误执行了大约15个不同的堆栈溢出问题之后,我还有另一个关于无法启动活动ComponentInfo的问题. ?xml version="1.0" encoding="utf-8"?manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hauntingong
因此,在对同一错误执行了大约15个不同的堆栈溢出问题之后,我还有另一个关于无法启动活动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>

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

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文件

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

最后是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.

您需要在清单上添加此项

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读