得到错误而启动谷歌地图V2 [英] Getting Error while starting Google Map v2

查看:96
本文介绍了得到错误而启动谷歌地图V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到这个错误了一整天:

I've been seeing this error for a whole day:

    06-18 15:40:14.343: E/AndroidRuntime(11830): FATAL EXCEPTION: main
06-18 15:40:14.343: E/AndroidRuntime(11830): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.os.Looper.loop(Looper.java:137)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.ActivityThread.main(ActivityThread.java:4921)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at java.lang.reflect.Method.invokeNative(Native Method)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at java.lang.reflect.Method.invoke(Method.java:511)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at dalvik.system.NativeStart.main(Native Method)
06-18 15:40:14.343: E/AndroidRuntime(11830): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.Activity.setContentView(Activity.java:1924)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.example.googlemap.MainActivity.onCreate(MainActivity.java:21)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.Activity.performCreate(Activity.java:5188)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
06-18 15:40:14.343: E/AndroidRuntime(11830):    ... 11 more
06-18 15:40:14.343: E/AndroidRuntime(11830): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4452000 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" />
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.maps.internal.u.B(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.maps.internal.u.A(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.maps.MapFragment$b.ip(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.dynamic.a.a(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.app.Activity.onCreateView(Activity.java:4838)
06-18 15:40:14.343: E/AndroidRuntime(11830):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
06-18 15:40:14.343: E/AndroidRuntime(11830):    ... 21 more

我跟很多的问题和答案在SO,但结果是一样的。

I have followed a lot questions and answers on SO, yet the result is same.

我的清单是:

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

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="17" />

    <permission
        android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <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" >
        <activity
            android:name="com.example.googlemap.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="something-something" />
    </application>

</manifest>

我的MainActivity.java:

My MainActivity.java:

import android.app.Activity;
import android.os.Bundle;      
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {
      static final LatLng HAMBURG = new LatLng(53.558, 9.927);
      static final LatLng KIEL = new LatLng(53.551, 9.993);
      private GoogleMap map;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
            .title("Hamburg"));
        Marker kiel = map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory
                .fromResource(R.drawable.ic_launcher)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
      }
}

我的布局文件:

My layout File:

<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"
    tools:context=".MainActivity" >

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

</RelativeLayout> 

这是完全一样的,因为我从一些网站获得。任何人都可以帮助我在这里?谢谢!!

It's exactly the same as I got from some of the websites. Can anyone help me out here?? Thank you!!

推荐答案

您locgcat说清楚

Your locgcat clearly said

Caused by: java.lang.IllegalStateException: The meta- data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 but found 0. You must have the following declaration within the element:

尝试添加使用谷歌播放服务版本&LT;元数据&GT; &LT标记;用途&gt; 标签在的manifest.xml 文件中像

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

这篇关于得到错误而启动谷歌地图V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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