0

I've spent the last few hours trying to figure out what I'm doing wrong. I am trying to make a basic map app using Google Maps for Android v2 but I am getting this error.

    01-05 15:34:10.878: E/AndroidRuntime(22687): FATAL EXCEPTION: main
01-05 15:34:10.878: E/AndroidRuntime(22687): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapapp/com.example.mapapp.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.ActivityThread.access$600(ActivityThread.java:151)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.os.Looper.loop(Looper.java:155)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.ActivityThread.main(ActivityThread.java:5536)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at java.lang.reflect.Method.invokeNative(Native Method)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at java.lang.reflect.Method.invoke(Method.java:511)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at dalvik.system.NativeStart.main(Native Method)
01-05 15:34:10.878: E/AndroidRuntime(22687): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:363)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.Activity.setContentView(Activity.java:1912)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.example.mapapp.MainActivity.onCreate(MainActivity.java:14)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.Activity.performCreate(Activity.java:5066)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
01-05 15:34:10.878: E/AndroidRuntime(22687):    ... 11 more
01-05 15:34:10.878: E/AndroidRuntime(22687): 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" />
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.maps.internal.q.v(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.maps.internal.q.u(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.dynamic.a.a(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
01-05 15:34:10.878: E/AndroidRuntime(22687):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)

I'm not sure what is going wrong but here is my MainActivity.java

package com.example.mapapp;


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

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;
    }

}

Here is my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<!-- This can go anywhere in your layout (see other demos for some examples). -->
<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.testing.svma.MainActivity"/>

and here is my AndroidManifest.xml

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

      <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
  <uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19"/>
  <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"/>
  <!-- External storage for caching. -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <!-- My Location -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <!-- Maps API needs OpenGL ES 2.0. -->
  <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
  <!-- End of copy. -->
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    <meta-data
            android:name="com.google.android.gms.version"
            android:value="CENSORED" />
        <activity
            android:name="com.example.mapapp.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>
    </application>

</manifest>

Any help would be GREATLY appreciated!

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • possible duplicate of [After Google Play Service update to version 13 I got an error](http://stackoverflow.com/questions/19723811/after-google-play-service-update-to-version-13-i-got-an-error) – laalto Jan 06 '14 at 08:16

1 Answers1

0

The class and android:name attributes have the same functionality. Change your fragment tag to the following:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.SupportMapFragment"/>

By doing android:name="com.example.mapapp.MainActivity" you are telling Android to use the MainActivity as if it were a Fragment.

Also your AndroidManifest.xml is not configured properly with Google Maps V2. This meta tag in particular:

 <meta-data
            android:name="com.google.android.gms.version"
            android:value="AIzaSyAl0-Oe2uYMSt40LFqxt5VMy0lXXX" />

Please refer to the google docs on how to properly configure Google Maps V2. Also, make sure you are importing the Google Maps library correctly.

As an advice, do not share your API Key with the world.

Emmanuel
  • 13,083
  • 4
  • 39
  • 53
  • Hmm ok thank you. I replaced my code with yours but I am still getting "Error inflating class fragment: – Grant price Jan 06 '14 at 02:46
  • Ok I censored my API key, would be great if you could do the same in your answer. I changed that tag to `` but still get the same error. Am I missing something? Thanks a ton – Grant price Jan 06 '14 at 03:50