i'am new in Android programming i have a problem. When my code running i give error "Unfortunately [app] has Stopped" in my device screen.
This is my Activity
package com.android.markermap;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
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 Activity {
static final LatLng BANDUNG = new LatLng(-6.904955,107.61034);
static final LatLng BOGOR = new LatLng(-6.589581,106.799755);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker bandung = map.addMarker(new MarkerOptions().position(BANDUNG).title("Berat"));
Marker bogor = map.addMarker(new MarkerOptions().position(BOGOR).title("Ringan").snippet("Kiel is cool"));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(BANDUNG, 12));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
This is my layout code
<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"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.markermap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<permission
android:name="com.android.markermap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.android.markermap.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.android.markermap.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="AIzaSyC-0N7OEKJmId5HnKYNsbU6IBaSIgiF7Lc" />
</application>
</manifest>
And this is my error code
11-30 23:39:58.071: W/dalvikvm(16870): threadid=1: thread exiting with uncaught exception (group=0x40c64438)
11-30 23:39:58.071: E/AndroidRuntime(16870): FATAL EXCEPTION: main
11-30 23:39:58.071: E/AndroidRuntime(16870): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.markermap/com.android.markermap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.ActivityThread.access$600(ActivityThread.java:133)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.os.Looper.loop(Looper.java:137)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.ActivityThread.main(ActivityThread.java:4810)
11-30 23:39:58.071: E/AndroidRuntime(16870): at java.lang.reflect.Method.invokeNative(Native Method)
11-30 23:39:58.071: E/AndroidRuntime(16870): at java.lang.reflect.Method.invoke(Method.java:511)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
11-30 23:39:58.071: E/AndroidRuntime(16870): at dalvik.system.NativeStart.main(Native Method)
11-30 23:39:58.071: E/AndroidRuntime(16870): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:262)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.Activity.setContentView(Activity.java:1867)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.android.markermap.MainActivity.onCreate(MainActivity.java:23)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.Activity.performCreate(Activity.java:5008)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)
11-30 23:39:58.071: E/AndroidRuntime(16870): ... 11 more
11-30 23:39:58.071: E/AndroidRuntime(16870): 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" />
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.maps.internal.q.v(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.maps.internal.q.u(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.dynamic.a.a(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.app.Activity.onCreateView(Activity.java:4663)
11-30 23:39:58.071: E/AndroidRuntime(16870): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-30 23:39:58.071: E/AndroidRuntime(16870): ... 21 more
Anyonee have ide for this problem?
i'am very confuse, i hope u can solve this problem.
actually reading the error help a lot you know
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" />
Your code is fine but for Google play service revision 13 you should have to add one more meta tag in your manifest.xml.Insert it inside your application tag.So there will be two meta tags in your application tag.If you still need any help.Just follow this link
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
Related
I am trying to run Google maps API v2 on emulator. It says "unfortunately app has stoped" Here is my manifest.xml code. There is a huge number of errors. In the first line it gives error to define android.allowBackup which I have done on application tag.Please help me solve them.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
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.ACCESS_NETWORK_STATE"/>
<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-permissionandroid:name="com.myapp.providers.gsf.permission.
READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:hardwareAccelerated="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="4030500" />
<!-- <meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" /> -->
<activity
android:name="com.myapp.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="My key"/>
</application>
</manifest>
----------------------------------------------------------------------------------------------
MainActivity.java
package myapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = mapFrag.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
------------------------------------------------------------------------------------
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"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
-----------------------------------------------------------------
Logcat
E/Trace(690): error opening trace file: No such file or directory (2)
E/AndroidRuntime(690): FATAL EXCEPTION: main
E/AndroidRuntime(690): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{myapp/myapp.MainActivity}:android.view.InflateException: Binary XML file line #2:
Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:06:56.709: E/AndroidRuntime(690): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.
java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
AndroidRuntime(690): ... 11 more
AndroidRuntime(690): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:06:56.709: E/AndroidRuntime(690): ... 23 more
09-01 15:07:53.868: E/Trace(734): error opening trace file: No such file or directory (2)
09-01 15:07:54.479: E/AndroidRuntime(734): FATAL EXCEPTION: main
09-01 15:07:54.479: E/AndroidRuntime(734): java.lang.RuntimeException:
Unable to start activity ComponentInfo{myapp/myapp.MainActivity}
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:07:54.479: E/AndroidRuntime(734): Caused by:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.
setContentView(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime(734): ... 11 more
E/AndroidRuntime(734): Caused by: java.lang.IllegalStateException: The meta-data tag in your
app's AndroidManifest.xml does not have the right value. Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:07:54.479: E/AndroidRuntime(734): ... 23 more
error opening trace file: No such file or directory (2)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{myapp/myapp.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:12:22.938: E/AndroidRuntime(811): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView
(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-01 15:12:22.938: E/AndroidRuntime(811): ... 11 more
09-01 15:12:22.938: E/AndroidRuntime(811): Caused by: java.lang.IllegalStateException: The meta-
data tag in your app's AndroidManifest.xml does not have the right value. Expected 5089000
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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:19:34.508: E/Trace(826): error opening trace file: No such file or directory (2)
09-01 15:19:35.118: E/AndroidRuntime(826): FATAL EXCEPTION: main
09-01 15:19:35.118: E/AndroidRuntime(826): java.lang.RuntimeException:
Unable to start activity ComponentInfo{myapp/myapp.MainActivity}: android.view.InflateException:
Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:19:35.118: E/AndroidRuntime(826): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView
(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-01 15:19:35.118: E/AndroidRuntime(826): ... 11 more
09-01 15:19:35.118: E/AndroidRuntime(826): Caused by: java.lang.IllegalStateException:
The meta- data tag in your app's AndroidManifest.xml does not
have the right value. Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailabl
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:27:57.068: E/Trace(865): error opening trace file: No such file or directory (2)
09-01 15:27:57.748: E/AndroidRuntime(865): FATAL EXCEPTION: main
09-01 15:27:57.748: E/AndroidRuntime(865): java.lang.RuntimeException:
Unable to start activity ComponentInfo{myapp/myapp.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:27:57.748: E/AndroidRuntime(865): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView
(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-01 15:27:57.748: E/AndroidRuntime(865): ... 11 more
09-01 15:27:57.748: E/AndroidRuntime(865): Caused by: java.lang.IllegalStateException:
The meta- data tag in your app's AndroidManifest.xml does not have the right value.
Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:27:57.748: E/AndroidRuntime(865): ... 23 more
mmmh... Change
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
to
<meta-data android:name="com.google.android.gms.version" android:value="5089000" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<permission
android:name="com.myapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.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.myapp."Your activity name""
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="Your map key" />
</application>
</manifest>
Add the below permission to your Manifest.xml
<permission android:name="com.myapp.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
and replaca the below line:
<uses-permissionandroid:name="com.myapp.providers.gsf.permission.
READ_GSERVICES"/>
via
<uses-permission android:name="com.myapp.providers.gsf.permission.
READ_GSERVICES"/>
I develop an application and I need to see the Google Maps v2.
The main class is:
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.app.Activity;
public class MapsV2 extends FragmentActivity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapsv2);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
Marker ciu = mMap.addMarker(new MarkerOptions()
.position(CIU).title("My Office"));
}
#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_page_option_menu, menu);
return true;
}
}
And the XML 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"
android:name="com.app.reminder.MapsV2"/>
So, when I run it on my device I've got error message:
02-18 14:20:37.596: E/AndroidRuntime(30383): FATAL EXCEPTION: main
02-18 14:20:37.596: E/AndroidRuntime(30383): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.reminder/com.app.reminder.MapsV2}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.access$600(ActivityThread.java:140)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.os.Handler.dispatchMessage(Handler.java:99)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.os.Looper.loop(Looper.java:137)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.main(ActivityThread.java:4898)
02-18 14:20:37.596: E/AndroidRuntime(30383): at java.lang.reflect.Method.invokeNative(Native Method)
02-18 14:20:37.596: E/AndroidRuntime(30383): at java.lang.reflect.Method.invoke(Method.java:511)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
02-18 14:20:37.596: E/AndroidRuntime(30383): at dalvik.system.NativeStart.main(Native Method)
02-18 14:20:37.596: E/AndroidRuntime(30383): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.Activity.setContentView(Activity.java:1924)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.app.reminder.MapsV2.onCreate(MapsV2.java:22)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.Activity.performCreate(Activity.java:5206)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
02-18 14:20:37.596: E/AndroidRuntime(30383): ... 11 more
02-18 14:20:37.596: E/AndroidRuntime(30383): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 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" />
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.internal.q.v(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.internal.q.u(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.SupportMapFragment$b.eb(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.dynamic.a.a(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
02-18 14:20:37.596: E/AndroidRuntime(30383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-18 14:20:37.596: E/AndroidRuntime(30383): ... 20 more
The manifest is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.reminder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<permission
android:name="com.app.reminder.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.app.reminder.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="com.app.reminder.InfoManager">
>
<activity
android:name="SplashScreen"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="MapsV2"></activity><uses-library android:name="com.google.android.maps"
/>
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBDtXP5sYucD8z5pjaJFuvt43sLWOGzyuQ" />
<activity android:name="MapsV2"></activity>
</application>
</manifest>
I tried all the options in the answers in StackOverFlow.
The log is quite clear, you are missing this line in your manifest:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
As you can read at the end of this line:
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 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" />
Also, take care to have the last version of Google Play services(version 13 or more), and not Google Play services for Froyo, who doesn't contain that parameter.
You should replace this
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
With
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
Replace your Fragment
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
In manifest.xml
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
Activity class
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
I am developing a simple Android app which uses the Google Maps API,
I had registered with Google for the API key and added it to my app but I am getting an error:
FATAL EXCEPTION: main
Process: com.s56.maps, PID: 866
12-17 09:28:56.070: E/AndroidRuntime(866): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.s56.maps/com.s56.maps.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.os.Handler.dispatchMessage(Handler.java:102)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.os.Looper.loop(Looper.java:137)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-17 09:28:56.070: E/AndroidRuntime(866): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 09:28:56.070: E/AndroidRuntime(866): at java.lang.reflect.Method.invoke(Method.java:515)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-17 09:28:56.070: E/AndroidRuntime(866): at dalvik.system.NativeStart.main(Native Method)
12-17 09:28:56.070: E/AndroidRuntime(866): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Activity.setContentView(Activity.java:1928)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.s56.maps.MainActivity.onCreate(MainActivity.java:19)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Activity.performCreate(Activity.java:5243)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-17 09:28:56.070: E/AndroidRuntime(866): ... 11 more
***12-17 09:28:56.070: E/AndroidRuntime(866): 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" />***
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.internal.q.v(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.internal.q.u(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Activity.onCreateView(Activity.java:4784)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
12-17 09:28:56.070: E/AndroidRuntime(866): ... 21 more
And my XML file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.s56.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
/>
<permission
android:name="com.s56.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-permission
android:name="com.s56.maps.permission.MAPS_RECEIVE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.s56.maps.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="A***MY_API_KEY***M"/>
</application>
</manifest>
and my activity_main.xml has
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
And my main class i.e activity class has,
public class MainActivity extends Activity
{
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap=
((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
final LatLng CIU = new LatLng(17.426944259701596, 78.5340459823017);
Marker c = mMap.addMarker(new MarkerOptions()
.position(CIU).title("s56 labs"));
}
#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;
} }
I had added Google Play services as library to Eclipse work space.
Kindly help me with this, and I am new to Android.
You must add this to your AndroidManifest.xml:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I have made an app that uses Google Android Maps API V2 and I have followed every step in the guide provided by Google but it doesn't work unfortunely and it crashes every time I try to start it up. So I'm wondering what is the problem?
MainActivity.java
package com.android.maptest;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
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"
android:name="com.google.android.gms.maps.MapFragment"/>
Maptest Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.maptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<permission
android:name="com.android.maptest.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.android.maptest.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"
android:debuggable="true" >
<activity
android:name="com.android.maptest.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="api_key" />
</application>
</manifest>
Logcat
03-12 09:46:13.150: D/AndroidRuntime(1547): Shutting down VM
03-12 09:46:13.150: W/dalvikvm(1547): threadid=1: thread exiting with uncaught exception (group=0x410e22a0)
03-12 09:46:13.155: E/AndroidRuntime(1547): FATAL EXCEPTION: main
03-12 09:46:13.155: E/AndroidRuntime(1547): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.maptest/com.android.maptest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-12 09:46:13.155: E/AndroidRuntime(1547): at
android.app.ActivityThread.access$600(ActivityThread.java:140)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.os.Handler.dispatchMessage(Handler.java:99)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.os.Looper.loop(Looper.java:137)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.reflect.Method.invoke(Method.java:511)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-12 09:46:13.155: E/AndroidRuntime(1547): at dalvik.system.NativeStart.main(Native Method)
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.setContentView(Activity.java:1924)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.maptest.MainActivity.onCreate(MainActivity.java:11)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.performCreate(Activity.java:5206)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 11 more
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:584)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:552)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.onCreateView(Activity.java:4849)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 20 more
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:574)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 23 more
03-12 09:51:21.560: I/Process(1547): Sending signal. PID: 1547 SIG: 9
Here a blog post I wrote on how to integrate Google Maps into you application:
Creating Google Map Application
From your error it look like you did not perform correctly steps 2-3 of the blog guide,
for adding Google Play services library into your application.
If you follow carefully the steps written in the guide you will end up with the end result you can see at the end of the post.
I assumed that you have already get Google Maps Android API v2 key and have Google Play services. If you not have already installed it then please follow below steps to solve this problem_
Step 1. you can found it in Android SDK Manager under Extras tick check box of -Google Play services install it and after complete installation, restart your Eclipse.
Step 2. Add library named_ google-play-services_lib found under the extras folder of your Android SDK setup folder to your Android project_
Path of google service lib_
{Your_Android_SDK_direct}\extras\google\google_play_services\libproject\google-play-services_lib
Ex. Location of this lib on My system_
C:\Program Files\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib
I hope this will solve your ploblem.
For me adding:
import com.google.android.gms.maps.SupportMapFragment;
And changing the xml to
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header" />
resolved the problem. I hope you resolve it too!
Looks like you didn't add the Google Play Services library to your project.
It's located at {Android SDK}\extras\google\google_play_services
Add it as Android Library Project to Eclipse and then add it to your project.
I am trying to run a basic example of Google maps API v2 from http://www.vogella.com/articles/AndroidGoogleMaps/article.html but it keeps crashing with an error:
02-10 14:51:38.292: E/AndroidRuntime(898): FATAL EXCEPTION: main
02-10 14:51:38.292: E/AndroidRuntime(898): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
02-10 14:51:38.292: E/AndroidRuntime(898): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
02-10 14:51:38.292: E/AndroidRuntime(898): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.Activity.onCreateView(Activity.java:4716)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-10 14:51:38.292: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.Activity.setContentView(Activity.java:1881)
02-10 14:51:38.292: E/AndroidRuntime(898): at com.vogella.android.locationapi.maps.MainActivity.onCreate(MainActivity.java:23)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.Activity.performCreate(Activity.java:5104)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.os.Looper.loop(Looper.java:137)
02-10 14:51:38.292: E/AndroidRuntime(898): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-10 14:51:38.292: E/AndroidRuntime(898): at java.lang.reflect.Method.invokeNative(Native Method)
02-10 14:51:38.292: E/AndroidRuntime(898): at java.lang.reflect.Method.invoke(Method.java:511)
02-10 14:51:38.292: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-10 14:51:38.292: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-10 14:51:38.292: E/AndroidRuntime(898): at dalvik.system.NativeStart.main(Native Method)
my code...
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vogella.android.locationapi.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.mapdemo.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.vogella.android.locationapi.maps.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="{tried both browser api key and android api keys here}" />
</application>
</manifest>
layout:
<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"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
Activity:
package com.vogella.android.locationapi.maps;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
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 Activity {
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 = ((MapFragment) getFragmentManager().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) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
of ran it on an AVD with target Google API 17, it crashes immediately.
I noticed you have not added protection for Google Play Services, the Google Maps V2 api requires this to run.
The issue maybe due to Google Play Services not being supported on AVD. Try running on a device.
maybe these can help
Missing Google Play Services from AVD
https://stackoverflow.com/a/14282347/1788333
You should extend FragmentActivity than Activity.
Use this in your activity:
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
And in xml in fragment tag write this:
class="com.google.android.gms.maps.SupportMapFragment"