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:
a library
.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
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.
I know this is probably a dead thread but just in case someone stumbles upon here having an identical problem - your manifest might be missing the following meta information:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Declare it within the <application>
element and your code should work. I ran into the same issue following a youtube tutorial that skipped this step and only when carefully going through the original Google tutorial I noticed the missing code.
Anyway, hope this helps someone.
I have the same code/same problem! Try adding android:name="com.testing.svma.MainActivity" to "fragment" in the layout! It solved the issue for me
<?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.testing.svma.MainActivity"/>
I had the same problem, solved it by modifying the Manifest. This is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.gps"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="example.gps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17"/>
<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"
android:hardwareAccelerated="true" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<YOUR VALUE>"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="example.gps.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>
And the xml file is
<?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"
/>
The java class is
public class MainActivity extends FragmentActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
That solved my problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With