另一个谷歌地图v2无法膨胀PLEASE

时间:2014-05-13 11:27:46

标签: java android google-maps layout-inflater inflate-exception

我知道有很多关于此的帖子,但我无法让我的谷歌地图工作。我已经尝试了百万种不同的方式来获得这个,我发现最好的方法是这样的:

MainActivity.java

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

activity_main.xml中

<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
        xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      class="com.google.android.gms.maps.SupportMapFragment"
     android:name="in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity"/>

</RelativeLayout>

的Manifest.xml

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

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="19" />

    <permission
          android:name="in.wptrafficanalyzer.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>

    <uses-permission android:name="in.wptrafficanalyzer.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"/>

    <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"/>


    <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="in.wptrafficanalyzer.locationgooglemapv2demo.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="AIzaSyAxS05MA_zbMWq27N83FOqKh7MlwLz-2Lg"/>        

    </application>

</manifest>

但我仍然得到很多人得到的这个错误:( 我实施了google-play-services_lib

 05-13 13:18:39.673: E/ActivityThread(14542): Failed to inflate
 05-13 13:18:39.673: E/ActivityThread(14542): android.view.InflateException: Binary XML           file line #7: Error inflating class fragment
 05-13 13:18:39.673: E/ActivityThread(14542):   at      android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
 05-13 13:18:39.673: E/ActivityThread(14542):   at      android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.Activity.setContentView(Activity.java:1881)
 05-13 13:18:39.673: E/ActivityThread(14542):   at in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity.onCreate(MainActivity.java:12)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.Activity.performCreate(Activity.java:5122)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2432)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2530)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.ActivityThread.access$600(ActivityThread.java:176)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1385)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.os.Handler.dispatchMessage(Handler.java:107)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.os.Looper.loop(Looper.java:194)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.app.ActivityThread.main(ActivityThread.java:5546)
 05-13 13:18:39.673: E/ActivityThread(14542):   at java.lang.reflect.Method.invokeNative(Native Method)
 05-13 13:18:39.673: E/ActivityThread(14542):   at java.lang.reflect.Method.invoke(Method.java:525)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
 05-13 13:18:39.673: E/ActivityThread(14542):   at dalvik.system.NativeStart.main(Native Method)
 05-13 13:18:39.673: E/ActivityThread(14542): 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 <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.maps.internal.q.B(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.maps.internal.q.A(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.dynamic.a.a(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
 05-13 13:18:39.673: E/ActivityThread(14542):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
 05-13 13:18:39.673: E/ActivityThread(14542):   ... 21 more
 05-13 13:18:39.683: E/AndroidRuntime(14542): FATAL EXCEPTION: main
 05-13 13:18:39.683: E/AndroidRuntime(14542): java.lang.RuntimeException: Unable to start activity      ComponentInfo{in.wptrafficanalyzer.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2478)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2530)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.ActivityThread.access$600(ActivityThread.java:176)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1385)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.os.Handler.dispatchMessage(Handler.java:107)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.os.Looper.loop(Looper.java:194)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.ActivityThread.main(ActivityThread.java:5546)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at java.lang.reflect.Method.invokeNative(Native Method)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at java.lang.reflect.Method.invoke(Method.java:525)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at dalvik.system.NativeStart.main(Native Method)
 05-13 13:18:39.683: E/AndroidRuntime(14542): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.Activity.setContentView(Activity.java:1881)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity.onCreate(MainActivity.java:12)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.Activity.performCreate(Activity.java:5122)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2432)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   ... 11 more
 05-13 13:18:39.683: E/AndroidRuntime(14542): 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 <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.maps.internal.q.B(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.maps.internal.q.A(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.dynamic.a.a(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   at                android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
 05-13 13:18:39.683: E/AndroidRuntime(14542):   ... 21 more

请有人可以帮助我...我正在尝试制作简单的谷歌地图应用程序超过一个月,我用完了选项...... :(

1 个答案:

答案 0 :(得分:2)

你的logcat清楚地说了

  

引起:java.lang.IllegalStateException:你的元数据标签   应用程序的AndroidManifest.xml没有正确的值。预期   4323000但找到0.您必须在其中包含以下声明   元素:

您需要使用<meta-data>文件中<application>标记下的manifest.xml标记添加Google Play服务版本

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