Reputation: 1967
I am trying to add google map v2 and here is the main layout xml:
<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" >
<com.test.map.CustomAutoCompleteTextView
android:id="@+id/atv_places"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="@string/str_atv_places"
android:singleLine="true" />
<fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@id/atv_places" />
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<permission
android:name="com.test.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.test.map.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" />
<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.test.map.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="mykey" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
I have imported the play services library project and a copy of it in workspace
The above steps are taken from documentations provided by google. Now that, everything seems to be perfect and in place, I get the following exception:
02-09 11:39:30.227: E/AndroidRuntime(5153): FATAL EXCEPTION: main
02-09 11:39:30.227: E/AndroidRuntime(5153): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.map/com.test.map.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.os.Looper.loop(Looper.java:137)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.main(ActivityThread.java:5103)
02-09 11:39:30.227: E/AndroidRuntime(5153): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 11:39:30.227: E/AndroidRuntime(5153): at java.lang.reflect.Method.invoke(Method.java:525)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-09 11:39:30.227: E/AndroidRuntime(5153): at dalvik.system.NativeStart.main(Native Method)
02-09 11:39:30.227: E/AndroidRuntime(5153): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.Activity.setContentView(Activity.java:1895)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.test.map.MainActivity.onCreate(MainActivity.java:53)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.Activity.performCreate(Activity.java:5133)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
02-09 11:39:30.227: E/AndroidRuntime(5153): ... 11 more
02-09 11:39:30.227: E/AndroidRuntime(5153): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.internal.q.v(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.internal.q.u(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.SupportMapFragment$b.eb(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.dynamic.a.a(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-09 11:39:30.227: E/AndroidRuntime(5153): ... 21 more
Logcat is saying the following tag is missing, though I have it in my manifest.
02-09 11:39:30.227: E/AndroidRuntime(5153): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
Why I get this issue though everything is in place? Any help is appreciated.
Upvotes: 0
Views: 207
Reputation: 4039
Could you please use FrameLayout
instead of Fragment
in the layout file. Then create an instance of supportmapfragment
in code and replace the FrameLayout
with this fragment. It will solve your issue.
XML:
<FrameLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
In Code:
FragmentManager fm = getSupportFragmentManager();
SupportMapFragment supportMapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, supportMapFragment).commit();
Upvotes: 2
Reputation: 2530
The meta-data tag must be a child of the application tag:
<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.maps.v2.API_KEY"
android:value="mykey" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity ....
Upvotes: 1
Reputation: 1388
Don't forget to check your capitalization.
02-09 11:39:30.227: E/AndroidRuntime(5153): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
Looks like you forgot to capatalize the Fragment class name.
<Fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@id/atv_places" />
Upvotes: 1