Reputation: 3595
I'm trying to put together a working example of Google Maps Android API V2. I have found four tutorials that describe how to do this (DJ-android, Vogella, 2 tutorials from official docs) and none of them work. I have found nearly a dozen posts, like this one, from as many other developers, with exactly the same problem: "Binary XML file line #x Error inflating class". On stackoverflow, none of the dozen posts have a single accepted answer. I know of no working examples of this API anywhere on the internet.
The contents of my project are pasted below. I think I have everything that has been recommended from all those various posts but, like so many others, I'm getting this inflation run time error.
This actual project was taken from the Vogella tutorial which wouldn't even compile. I applied fixes from other posts of the same problem.
Can anyone tell me how to make this work? Does anyone know of a working example anywhere? Thanks, Gary
Manifest file...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mapdemo.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="I have a valid V2 key here" />
</manifest>
I have the Google Play services Library project in the workspace . . .
My main layout XML file . . .
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.mapdemo.MainActivity"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
The MainActivity.java file . . . (wish the code paste worked on this forum)
package com.example.mapdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends android.support.v4.app.FragmentActivity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}
the Logcat... (is there some secret to pasting this stuff?)
08-12 13:00:52.380: W/dalvikvm(8118): VFY: unable to resolve instance field 28
08-12 13:00:52.550: W/dalvikvm(8118): Unable to resolve superclass of Lmaps/p/w; (734)
08-12 13:00:52.550: W/dalvikvm(8118): Link of class 'Lmaps/p/w;' failed
08-12 13:00:52.550: W/dalvikvm(8118): Unable to resolve superclass of Lmaps/ap/as; (6056)
08-12 13:00:52.550: W/dalvikvm(8118): Link of class 'Lmaps/ap/as;' failed
08-12 13:00:52.550: W/dalvikvm(8118): Unable to resolve superclass of Lmaps/af/k; (5085)
08-12 13:00:52.550: W/dalvikvm(8118): Link of class 'Lmaps/af/k;' failed
08-12 13:00:52.550: E/dalvikvm(8118): Could not find class 'maps.af.k', referenced from method maps.ag.an.a
08-12 13:00:52.550: W/dalvikvm(8118): VFY: unable to resolve new-instance 4928 (Lmaps/af/k;) in Lmaps/ag/an;
08-12 13:00:52.681: W/dalvikvm(8118): threadid=1: thread exiting with uncaught exception (group=0x40017560)
08-12 13:00:52.691: E/AndroidRuntime(8118): FATAL EXCEPTION: main
08-12 13:00:52.691: E/AndroidRuntime(8118): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapdemo/com.example.mapdemo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.os.Looper.loop(Looper.java:130)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-12 13:00:52.691: E/AndroidRuntime(8118): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 13:00:52.691: E/AndroidRuntime(8118): at java.lang.reflect.Method.invoke(Method.java:507)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
08-12 13:00:52.691: E/AndroidRuntime(8118): at dalvik.system.NativeStart.main(Native Method)
08-12 13:00:52.691: E/AndroidRuntime(8118): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.Activity.setContentView(Activity.java:1657)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.example.mapdemo.MainActivity.onCreate(MainActivity.java:26)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-12 13:00:52.691: E/AndroidRuntime(8118): ... 11 more
08-12 13:00:52.691: E/AndroidRuntime(8118): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bb.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bb.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.an.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bi.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bh.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at blf.onTransact(SourceFile:107)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.os.Binder.transact(Binder.java:279)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.internal.bh$4.b(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.internal.bh.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.internal.bh.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
08-12 13:00:52.691: E/AndroidRuntime(8118): ... 20 more
Upvotes: 2
Views: 6354
Reputation: 2163
Add these meta data tags to the manifest file
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your api key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Upvotes: 0
Reputation: 309
I face the same problem as you...This happened when I updated my SDK to 4.4 kitkat..and Suddenly everything went haywire. I'm very familiar with Googlemapv2 apps
and have quite a few of them I developed before. But today all my googlemap apps got this error
Binary XML file line #x Error inflating class Fragment
whenever I run my compiled app...I suspect 4.4 updates for this error..Before this update nothing was wrong with vogella
and other gmapv2
tutorials.
Upvotes: 1
Reputation: 1007584
I know of no working examples of this API anywhere on the internet.
Here are 13 sample projects demonstrating the use of various aspects of Maps V2.
And I'm reasonably certain that some, if not all, of the samples you started with also work.
Can anyone tell me how to make this work?
With regards to:
08-12 13:00:52.691: E/AndroidRuntime(8118): Caused by: java.lang.RuntimeException: API key not found
You are getting that because your <meta-data>
element is in the wrong place. It needs to be a child of the <application>
element:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android.mapsv2.basic"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="false"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar">
<activity
android:name="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="AIzaSyC4iyT46cB00IdKGcy5EmAxK5uCOQX2Oy8"/>
<activity android:name="LegalNoticesActivity">
</activity>
</application>
</manifest>
Lars Vogel's Maps V2 tutorial, for example, has it in the right place.
Upvotes: 2