0

Im new to android development so im following basic tutorials online. I followed a google map v2 android tutorial.The Android app crashes with the error, "Unfortunately, my app has stopped working".I am using the most recent Android and Google Maps APIs (Android 4.2.2 and Google APIs 17).And I have done import the library project into project workspace[File > Import, select Android > Existing Android Code into Workspace].

MainActivity.java

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.main, menu);
    return true;
  }

} 

Main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

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

</RelativeLayout> 

AndroidManifest

<?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.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.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="My Map API Key"/>       
    </application>
</manifest>

No Errors displayed in LogCat.So how can I find out why the app crashes?Does anybody have any idea about it?

Jishin
  • 113
  • 2
  • 5
  • 12
  • there must be something wrong with Your logcat or You haven´t seen the output (is option "verbose", if not switch it). If Your app crash with this message, You must have an output in logcat. – Opiatefuchs Jun 26 '13 at 14:33
  • Can you clarify a few points: Are you using eclipse? which version? did you filter logcat? can you see logcat messages from other apps? how are you debuging? running on device or vm / which version of android are you running on? – Twisted Jun 26 '13 at 14:41
  • try to make your logcat level to 'Verbose' or put breakpoints in arbitrary points and debug it, it will guide you through – Onur A. Jun 26 '13 at 14:51
  • @Twisted yeah..am using Eclipse 4.2..I am using the most recent Android and Google Maps APIs (Android 4.2.2 and Google APIs 17).My app running on emulator android 4.2.2 API-17. – Jishin Jun 27 '13 at 04:26
  • @OnurA. my logcat level is already set to 'Verbose'. – Jishin Jun 27 '13 at 04:29

2 Answers2

0

In your Android-Manifest:

android:value="My Map API Key"

Here your own API-Key has to be written into the quotation marks. You can create it here: https://code.google.com/apis/console/

And the Tutorial how to do that can be found here: https://developers.google.com/maps/documentation/android/start

You should use the debug certificate fingerprint, not one for the release.

Cerdo
  • 33
  • 1
  • 1
  • 5
0

Edit your application's AndroidManifest.xml file, and add the following declaration within the element. This embeds the version of Google Play services that the app was compiled with.

This is a new requirement as of the updated google play services which is rev 13 i guess.

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Attaullah
  • 3,856
  • 3
  • 48
  • 63