0

I've spent 24 hours trying to deploy a simple google maps v2 android apps. I've searched in a lot of forums (included stackoverflow)... but I'm desperated. The error is:

android.view.InflateException: Binary XML file line #7: Error inflating class fragment

Here is the 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" />

MainActivity.java

package com.gotme.gotmemaps;

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.main, menu);
        return true;
    }

}

AndroidManifest.xml

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

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

<permission

    android:name="com.gotme.gotmemaps.permission.MAPS_RECEIVE"

    android:protectionLevel="signature"/>

<uses-permission
    android:name="com.gotme.gotmemaps.permission.MAPS_RECEIVE"/>

<uses-permission
    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<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.gotme.gotmemaps.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="AIzaSyDHfwlSoRWb6xDrpowyMWWap9Du5LQCVRM"/>
    </application>


</manifest>

I have installed the library *google_play_services_lib* but always get the same error... Could somebody help me?

Thanks a lot!

UPDATE:

Here is my logcat:

11-19 12:25:23.745: E/AndroidRuntime(7163): FATAL EXCEPTION: main
11-19 12:25:23.745: E/AndroidRuntime(7163): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gotme.gotmemaps/com.gotme.gotmemaps.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.os.Looper.loop(Looper.java:137)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.ActivityThread.main(ActivityThread.java:4898)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at java.lang.reflect.Method.invokeNative(Native Method)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at java.lang.reflect.Method.invoke(Method.java:511)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at dalvik.system.NativeStart.main(Native Method)
11-19 12:25:23.745: E/AndroidRuntime(7163): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.Activity.setContentView(Activity.java:1924)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.gotme.gotmemaps.MainActivity.onCreate(MainActivity.java:16)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.Activity.performCreate(Activity.java:5206)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
11-19 12:25:23.745: E/AndroidRuntime(7163):     ... 11 more
11-19 12:25:23.745: E/AndroidRuntime(7163): 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-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.dynamic.a.a(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
11-19 12:25:23.745: E/AndroidRuntime(7163):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
11-19 12:25:23.745: E/AndroidRuntime(7163):     ... 21 more
user2076905
  • 3
  • 1
  • 4

2 Answers2

0

Assuming you have got the correct jars..etc. Your xml seems fine. here is what you can try doing.

public class MainActivity extends android.support.v4.app.FragmentActivity  {

    private GoogleMap mMap;

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

     // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        if (mMap== null)
        {
            Toast.makeText(this,"Google Maps not Available",
                    Toast.LENGTH_LONG).show();
        }


    }

Now, why this.. You have chosen min sdk as 8. FragmentActivity works only for API 11+, to make it compatible for below versions also, you need to extend it the way I have done.

Also, in your OnCreate I see absolutely nothing, there is no map instance created by you. What are you expecting to show on the screen?

ayush1794
  • 101
  • 1
  • 7
  • First of all, thank you for your time. I tried your changes but the error I get is the same. And you see OnCreate empty because I have been trying to isolate the error, so my OnCreate only displays the fragment. Even doing this, I get the same error. – user2076905 Nov 19 '13 at 07:12
  • can you please post the whole logcat error rather than just this first line..it may become more clear. – ayush1794 Nov 19 '13 at 11:17
0

try to add
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
into AndroidManifest.xml
It works for me!

PageNotFound
  • 2,320
  • 2
  • 23
  • 34