Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I submitted an similar question earlier on a more advanced project, so I thought I would simplify things by using the maps API tutorial provided by google to try and replicate the error I was getting, and I get the same error! Good and bad, at least I know it's not my project causing the error.

Now I just need to figure out why I am getting this error! I am new to programming but I followed this tutorial here verbatum:

https://developers.google.com/maps/documentation/android/start

Here is the error I am getting:

03-24 20:47:03.244: E/AndroidRuntime(6250): FATAL EXCEPTION: main
03-24 20:47:03.244: E/AndroidRuntime(6250): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.os.Looper.loop(Looper.java:137)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.ActivityThread.main(ActivityThread.java:5103)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at java.lang.reflect.Method.invokeNative(Native Method)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at java.lang.reflect.Method.invoke(Method.java:525)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at dalvik.system.NativeStart.main(Native Method)
03-24 20:47:03.244: E/AndroidRuntime(6250): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.Activity.setContentView(Activity.java:1895)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.example.test.MainActivity.onCreate(MainActivity.java:11)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.Activity.performCreate(Activity.java:5133)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-24 20:47:03.244: E/AndroidRuntime(6250):     ... 11 more
03-24 20:47:03.244: E/AndroidRuntime(6250): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 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" />
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.dynamic.a.a(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.app.Activity.onCreateView(Activity.java:4745)
03-24 20:47:03.244: E/AndroidRuntime(6250):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
03-24 20:47:03.244: E/AndroidRuntime(6250):     ... 20 more

Here is my simple MainActivity.java

package com.example.test;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

here is my simple activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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="com.example.test.MainActivity"/>

Here is my manifest:

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


    <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<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"/>

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.test.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="HIDDEN"/>
    </application>

</manifest>

The only thing I can think of is that my manifest file is improperly set up. But I followed the instructions and Eclipse didn't give me an error on it. I am up in arms here trying to figure this out. Any help would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
105 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your logcat clearly said

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 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" />
03-24 20:47:03.244: E/AndroidRuntime(6250):     at    com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)

Add the Google Play services version to your app's manifest

Edit your application's AndroidManifest.xml file, and add the following declaration within the element. This embeds the version of Google Play services that the app was compiled with.

You need to add <meta-data> under <application> tag into your AndroidManifest.xml

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

This is because latest google play services requires a version name, which is to be mentioned using <meta-data .. /> inside AndroidManifest.xml

....<application>
 ..............
 <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Key" />

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

</application>

Also Extends your Activity to FragmentActivity

MainActivity extends FragmentActivity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...