I'm trying my hand and Android Application Development. I'm currently using Eclipse (I can't remember the version, whatever the newest is). I've crossed a bridge where I just can't seem to grasp what I'm doing wrong. I'm attempting to use the Google Maps V2 API. I've been through several documents and tried several techniques, all of which lead to the same error:
Android.view.Inflate Exception: Binary XML file line #2: Error inflating class fragment
I've been pounding my face into the keys for 2 days straight trying to grasp what I'm doing wrong here.
Things I've done:
- Started with a blank activity.
- Project -> Properties -> Android -> Project Build Target is Google APIs - 4.2 - API 17 - I've tried every other option as well (as long as above version 3.0, found it documented
- Added the google-play-services_lib to my Package Explorer. I indicated that the google-play-services_lib was indeed
a library
. - Project -> Properties -> Android -> Library -> Add -> and I choose the location to the google-play-services_lib.
- Included
android-support-v4.jar
as a dependency of my project.
I've tried so many different answers from questions similar to mine, but to no avail. :( I can usually figure these things out, but maybe I'm just too overloaded.
My package explorer tree in eclipse looks like
- google-play-services_lib
- Svma
Here's the code:>
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"/>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testing.svma"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.testing.svma.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.testing.svma.permission.MAPS_RECEIVE" />
<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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.testing.svma.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="SHA1_Generated_KEY_HERE" />
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
MainActivity.java
package com.testing.svma;
import android.os.Bundle;
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);
}
}
Reference Documents
I used “Error inflating class fragment” with google map to try and fix my issues.
I referenced This google maps quick start guide to create my project.
I had started initially with the sample code from the Introduction to the Google Maps Android V2 Api
A whole slew of SO questions.
So, SO Community, what am I doing wrong? Why am I unable to grasp this simple concept.
Thank you in advance.
In Some of android 6.0 mobile this exception is bug If unable to flat XML cause by
Then it is active bug in android https://issuetracker.google.com/issues/35827842
This can be solved by adding
I had the same problem and I did the mistake to only add one of the 2 following tags.
The actual error is really misleading, as you might be thinking of some API level UI issue.
Note that you are also missing one of these two
I had a similar error and I think it comes from this point: when I include the Google Play Service API I do not copy it in my workspace, I use the original one !!!
Note: You should be referencing a copy of the library that you copied to your source tree—you should not reference the library from the Android SDK directory.
Check this point.
I have got similar problem that I resolved by right click
project->tools>add support library
... andsetup library
I hope this help you
I spend a lot of time trying to solve this problem and after much reading and trying, I solved by changing the
public class MainActivity extends FragmentActivity
for this
public class MainActivity extends android.support.v4.app.FragmentActivity
I hope this can help you
using both meta data references was resolving the issue in my case: