0
votes

I would get google map on my emulator. I followed the instructions on When I run the application an error's message appears:Unfortunately DemoGoogleMapsV2 has stopped.

my androidmanifest.xml:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.demogooglemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.demogooglemapsv2.permission.MAPS_RECEIVE" />

<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"/>
<!-- The following two permissions are not required to use
Google Maps Android API, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>

<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

my activity_main.xml:

<android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>

my MainActivity.java:

 package com.demogooglemapsv2;
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);
}
}

the log error:

09-04 17:43:51.170: E/Trace(1477): error opening trace file: No such file or directory (2) 09-04 17:43:53.449: E/AndroidRuntime(1477): FATAL EXCEPTION: main 09-04 17:43:53.449: E/AndroidRuntime(1477): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.demogooglemapsv2/com.demogooglemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.ActivityThread.access$600(ActivityThread.java:141) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.os.Handler.dispatchMessage(Handler.java:99) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.os.Looper.loop(Looper.java:137) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.ActivityThread.main(ActivityThread.java:5041) 09-04 17:43:53.449: E/AndroidRuntime(1477): at java.lang.reflect.Method.invokeNative(Native Method) 09-04 17:43:53.449: E/AndroidRuntime(1477): at java.lang.reflect.Method.invoke(Method.java:511) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 09-04 17:43:53.449: E/AndroidRuntime(1477): at dalvik.system.NativeStart.main(Native Method) 09-04 17:43:53.449: E/AndroidRuntime(1477): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.Activity.setContentView(Activity.java:1881) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.demogooglemapsv2.MainActivity.onCreate(MainActivity.java:17) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.Activity.performCreate(Activity.java:5104) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 09-04 17:43:53.449: E/AndroidRuntime(1477): ... 11 more 09-04 17:43:53.449: E/AndroidRuntime(1477): 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 element: 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.maps.internal.u.I(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.maps.internal.u.H(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.maps.SupportMapFragment$b.jz(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.dynamic.a.a(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.dynamic.a.onInflate(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291) 09-04 17:43:53.449: E/AndroidRuntime(1477): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 09-04 17:43:53.449: E/AndroidRuntime(1477): ... 21 more

4
Show your full log of the error - Francesco verheye
API_KEY in Manifest isn't filled in too - Francesco verheye
I fill the API_Key but I can't show it to the public - P.A
@NaveenTamrakar: I aded the google_paly_service to my project - P.A

4 Answers

0
votes

Replace FragmentActivity in place of Activity, make sure you are entering right api key.

And in place of com.google.android.gms.maps.MapFragment use com.google.android.gms.maps.SupportMapFragment

Make sure google play services is installed on your device. That's why try to run the application on real device not on the emulator.

0
votes

Add the following activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment  
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"
          />
</LinearLayout>
0
votes

add this tag in your menifest file

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
0
votes

Hope your project and google-play-services_lib both are in same workspace and you have added it as library project in your application. If your API-Key is ok then you need to change like this.

1. add this meta-data inside application tag in manifest

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

2. As minSdkVersion="8" you should use SupportMapFragment so activity_main.xml looks like this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout> 

3. Instead of Activity you should extend FragmentActivity and use SupportFragmentManager()

public class MainActivity extends FragmentActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
      GoogleMap mMap = fm.getMap(); 
  }
}

Try to run it on real device or Genymotion's emulator after installing google-play-service. Otherwise you will face a crash