I'm trying to get the sample code of Android 'Google Maps Android API v2' working. I get the project built without errors. However, when I try to run the app in Everpad device , the app crashes immediately.
here is :
- The java code
package com.dvp.android.gallery;
public class GPS 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.gps);
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);
}
}
The Manifest:
<application android:icon="#drawable/ic_bardo" android:label="#string/app_name">
<activity android:name=".Acceuil"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Objets" android:label="Objets"> </activity>
<activity android:name=".GPS"
android:label="GPS">
</activity>
<activity android:name=".Detail" android:label="Detail"></activity>
<activity
android:name=".Galeries"
android:label="Galeries"
/>
<activity
android:name=".Evennements"
android:label="Evennements"/>
<activity
android:name=".Infos"
android:label="Infos"/>
</application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA0HMTTGLqlYaq6jOuS0imbjt7GmUHyK0c"/>
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="com.dvp.android.gallery.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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" />
</manifest>
The logcat output:
09-27 12:42:49.466: E/AndroidRuntime(5542): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dvp.android.gallery/com.dvp.android.gallery.GPS}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.os.Looper.loop(Looper.java:137)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.main(ActivityThread.java:4429)
09-27 12:42:49.466: E/AndroidRuntime(5542): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 12:42:49.466: E/AndroidRuntime(5542): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
09-27 12:42:49.466: E/AndroidRuntime(5542): at dalvik.system.NativeStart.main(Native Method)
09-27 12:42:49.466: E/AndroidRuntime(5542): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.Activity.setContentView(Activity.java:1835)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.dvp.android.gallery.GPS.onCreate(GPS.java:23)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.Activity.performCreate(Activity.java:4465)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-27 12:42:49.466: E/AndroidRuntime(5542): ... 11 more
09-27 12:42:49.466: E/AndroidRuntime(5542): Caused by: java.lang.RuntimeException: API key not found. Check that is in the element of AndroidManifest.xml
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bb.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bb.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.an.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bh.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bg.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at bob.onTransact(SourceFile:107)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.os.Binder.transact(Binder.java:297)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.dynamic.a$4.b(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.dynamic.a.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:806)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1010)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1108)
the XML :
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".GPS" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</LinearLayout>
Please help me . thanks
you just have to make your Activity extend FragmentActivity instead of Activity
This is because Google Map class has a fragment and for that you have to import android.support.v4. jar file... And add a map to your layout as a fragment you need to extends with FragmentActivity
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 just started using fragments on android and im having really bad time trying to start
a map fragment (on a full screen) inside a fragment activity - I have tried e-v-e-r-y-t-h-i-n-g -
1. Myproject>Android tools>Add support library
2. Adding the support and google play services as jar \ libs
3. restarting ecipse
nothing seem to help...
the attached is my logcat output -
09-27 20:49:09.421: E/AndroidRuntime(11714): FATAL EXCEPTION: main
09-27 20:49:09.421: E/AndroidRuntime(11714): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.telofun/com.telofun.FragmentMap}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.os.Looper.loop(Looper.java:150)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.main(ActivityThread.java:4385)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.reflect.Method.invoke(Method.java:507)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
09-27 20:49:09.421: E/AndroidRuntime(11714): at dalvik.system.NativeStart.main(Native Method)
09-27 20:49:09.421: E/AndroidRuntime(11714): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.Activity.setContentView(Activity.java:1742)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.telofun.FragmentMap.onCreate(FragmentMap.java:23)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
09-27 20:49:09.421: E/AndroidRuntime(11714): ... 11 more
09-27 20:49:09.421: E/AndroidRuntime(11714): Caused by: android.support.v4.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
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
09-27 20:49:09.421: E/AndroidRuntime(11714): ... 20 more
09-27 20:49:09.421: E/AndroidRuntime(11714): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in loader dalvik.system.PathClassLoader[/data/app/com.telofun-1.apk]
09-27 20:49:09.421: E/AndroidRuntime(11714): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
that is the layout -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
And the code -
package com.telofun;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.Marker;
public class FragmentMap extends FragmentActivity {
GoogleMap googleMap;
Marker marker = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_map);
// Getting Google Play availability status
int status = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if (status != ConnectionResult.SUCCESS) { // Google Play Services are
// not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
requestCode);
dialog.show();
} else { // Google Play Services are available
// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
googleMap = fm.getMap();
}
}
}
Change this
class="com.google.android.gms.maps.MapFragment"
to
class="com.google.android.gms.maps.SupportMapFragment"
Make sure you have referenced google play services library project properly.
As Raghunandan says change the MapFragment for SupportMapFragment. But I think it is not that simple. I had the same error and tried like 6 tutorials, and read all the documentation from google. And finnally I've got it running and displaying the map. This is how it works for me.
1.Remove the libraries google-play-services and android support-v4 from both your eclipse and your PC. 2.Download again it from de sdk-manager. 3.Follow the instructions [here] (https://developers.google.com/maps/documentation/android/intro#sample_code) go to Sample Code and do as it says. Check specially this Existing Android Code Into Workspace , do not import the libraries as projects, they won't work. 4.Change all your MapFragment for SupportMapFragment, don't foget to extend your Actvity to FragmentActivity (that was my fail). 5.Disable (if it is enabled) the build automatically option from your project. 6.Clean the project. 5.Enable the build automatically option.
It should work.
If it works but the maps don't show you should go to the API consolo and turn on the Google Android Maps v2 and turn off the Google Maps v2.
Hope you can fix it!
I'm trying to launch Google Earth 6.1 from my Android app with a specific KML file. Here is what I have:
File file = new File(Environment.getExternalStorageDirectory(), "master.kml");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.google-earth.kml+xml");
startActivity(intent);
My AndroidManifest.xml looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidscope"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
However, when I run I get an ActivityNotFoundException:
09-27 14:23:05.290: W/dalvikvm(3525): threadid=1: thread exiting with uncaught exception (group=0x400dc760)
09-27 14:23:05.290: E/AndroidRuntime(3525): FATAL EXCEPTION: main
09-27 14:23:05.290: E/AndroidRuntime(3525): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/master.kml typ=application/vnd.google-earth.kml+xml }
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1382)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Activity.startActivityForResult(Activity.java:3095)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Activity.startActivity(Activity.java:3201)
09-27 14:23:05.290: E/AndroidRuntime(3525): at com.example.androidscope.MainActivity$1.onClick(MainActivity.java:85)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.view.View.performClick(View.java:3122)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.view.View$PerformClick.run(View.java:11942)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.os.Handler.handleCallback(Handler.java:587)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.os.Looper.loop(Looper.java:132)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.ActivityThread.main(ActivityThread.java:4028)
09-27 14:23:05.290: E/AndroidRuntime(3525): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 14:23:05.290: E/AndroidRuntime(3525): at java.lang.reflect.Method.invoke(Method.java:491)
09-27 14:23:05.290: E/AndroidRuntime(3525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
09-27 14:23:05.290: E/AndroidRuntime(3525): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-27 14:23:05.290: E/AndroidRuntime(3525): at dalvik.system.NativeStart.main(Native Method)
I've noticed that if I add:
intent.setClassName("com.google.earth", "com.google.earth.EarthActivity");
then Google Earth loads but with no of the KML information. Does anyone have any ideas?
Uri earthURI = Uri.fromFile(kmlFile);
Intent earthIntent = new Intent(android.content.Intent.ACTION_VIEW, earthURI);
startActivity(earthIntent);
Intent earthIntent = new Intent(android.content.Intent.ACTION_VIEW, earthURI);
This seems to work fine on Android 5
Is there an Android 6 permissions change that breaks this intent?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapsandgps"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".Maps"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
i added also android api key but when program runs i get error
09-27 21:03:48.468: E/AndroidRuntime(215): Uncaught handler: thread main exiting due to uncaught exception
09-27 21:03:48.576: E/AndroidRuntime(215): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapsandgps/com.example.mapsandgps.Maps}: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.os.Looper.loop(Looper.java:123)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.main(ActivityThread.java:4363)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Method.invoke(Method.java:521)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-27 21:03:48.576: E/AndroidRuntime(215): at dalvik.system.NativeStart.main(Native Method)
09-27 21:03:48.576: E/AndroidRuntime(215): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.Activity.setContentView(Activity.java:1622)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.example.mapsandgps.Maps.onCreate(Maps.java:24)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
09-27 21:03:48.576: E/AndroidRuntime(215): ... 11 more
09-27 21:03:48.576: E/AndroidRuntime(215): Caused by: java.lang.reflect.InvocationTargetException
09-27 21:03:48.576: E/AndroidRuntime(215): at com.google.android.maps.MapView.(MapView.java:237)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Constructor.constructNative(Native Method)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
09-27 21:03:48.576: E/AndroidRuntime(215): ... 20 more
09-27 21:03:48.576: E/AndroidRuntime(215): Caused by: java.lang.IllegalArgumentException: You need to specify an API Key for each MapView. See the MapView documentation for details.
09-27 21:03:48.576: E/AndroidRuntime(215): at com.google.android.maps.MapView.(MapView.java:273)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.google.android.maps.MapView.(MapView.java:254)
09-27 21:03:48.576: E/AndroidRuntime(215): ... 24 more
09-27 21:03:48.786: E/dalvikvm(215): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
you are probably trying to run the application in an incorrect version of target API on your virtual machine:
Select a target version that shows "Google APIs" in the beginig of the name-
good luck.
You are missing things in your manifest:
1) Permissions required by Google Maps (in <manifest>):
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
2) Meta data, last elements of <application> (ie after activities and services):
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key_goes_here" />
Refer to this documentation for further instruction.
I have the following code in an activity to send the user to a different application:
public void goBack(View v) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.example.android.lifecycle", "com.example.android.lifecycle.DialogActivity"));
startActivity(intent);
}
The manifest file for the application is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.lifecycle"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity android:name=".ActivityA"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.example.android.lifecycle" />
</intent-filter>
</activity>
<activity android:name=".ActivityB" />
<activity android:name=".ActivityC" />
<activity android:name=".DialogActivity"
android:theme="#android:style/Theme.Dialog">
<action android:name="com.example.android.lifecycle" />
<action android:name="android.intent.action.MAIN" />
</activity>
</application>
</manifest>
However, when I click on the button which should send me to the new application, I get a message saying - The application has stopped unexpectedly. Please try again.
What am I doing wrong and how can I rectify this?
Thanks!!
09-27 14:08:42.763: E/AndroidRuntime(286): FATAL EXCEPTION: main
09-27 14:08:42.763: E/AndroidRuntime(286): java.lang.IllegalStateException: Could not execute method of the activity
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View$1.onClick(View.java:2072)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View.performClick(View.java:2408)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View$PerformClick.run(View.java:8816)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Handler.handleCallback(Handler.java:587)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Looper.loop(Looper.java:123)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invoke(Method.java:521)
09-27 14:08:42.763: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-27 14:08:42.763: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-27 14:08:42.763: E/AndroidRuntime(286): at dalvik.system.NativeStart.main(Native Method)
09-27 14:08:42.763: E/AndroidRuntime(286): Caused by: java.lang.reflect.InvocationTargetException
09-27 14:08:42.763: E/AndroidRuntime(286): at com.example.myfirstapp.DisplayMessageActivity.goBack(DisplayMessageActivity.java:30)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invoke(Method.java:521)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View$1.onClick(View.java:2067)
09-27 14:08:42.763: E/AndroidRuntime(286): ... 11 more
09-27 14:08:42.763: E/AndroidRuntime(286): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cmp=com.example.android.lifecycle/.DialogActivity } from ProcessRecord{450fce58 286:com.example.myfirstapp/10044} (pid=286, uid=10044) requires null
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Parcel.readException(Parcel.java:1247)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Parcel.readException(Parcel.java:1235)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.Activity.startActivityForResult(Activity.java:2817)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.Activity.startActivity(Activity.java:2923)
09-27 14:08:42.763: E/AndroidRuntime(286): ... 15 more
Add Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_FROM_BACKGROUND flags with intent if you are starting New Application from Background as:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName( "com.example.android.lifecycle","com.example.android.lifecycle.DialogActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);
I think in manifest file under activity android:name=".DialogActivity", the name should be
action android:name="com.example.android.lifecycle.DialogActivity"
Can you try?