Android Google Maps v2 Stopping
NickName:Kalyan Kumar Ask DateTime:2015-06-11T04:53:27

Android Google Maps v2 Stopping

I am new to Android and Google Maps v2 API. I tried to integrate the API in my app but I am getting:

Unfortunately, Map Example has stopped.

Can anyone help me finding the mistake?

MainActivity class:

import android.app.Activity;

import android.os.Bundle;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
 import com.google.android.gms.maps.MapFragment;

  public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    GoogleMap map;
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();

    if (map == null)
        Toast.makeText(getApplicationContext(),
                "Sorry! unable to create Map.", Toast.LENGTH_SHORT).show();
    else {
        // do somework here.

    }

    }

    }

activity_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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<!-- Google Maps API V2 -->

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

</RelativeLayout>

Androidmainfest.xml

<permission
    android:name="com.example.example.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" >
</permission>



 <uses-permission android:name="com.example.mapexample.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" />

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Sample"
        android:label="@string/title_activity_sample" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <!-- <uses-library android:name="com.google.android.maps"/> -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="6587000" />

    <!-- API KEY -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="API-KEY-HERE" />
</application> 

My logcat output

 06-10 21:03:06.610: E/dalvikvm(857): Could not find class 'com.google.android.gms.maps.MapFragment', referenced from method com.example.mapexample.MainActivity.onCreate
06-10 21:03:06.610: W/dalvikvm(857): VFY: unable to resolve check-cast 1271 (Lcom/google/android/gms/maps/MapFragment;) in Lcom/example/mapexample/MainActivity;
06-10 21:03:06.610: D/dalvikvm(857): VFY: replacing opcode 0x1f at 0x0014
06-10 21:03:06.670: D/AndroidRuntime(857): Shutting down VM
06-10 21:03:06.670: W/dalvikvm(857): threadid=1: thread exiting with uncaught exception (group=0xb1ae6d70)
06-10 21:03:06.880: E/AndroidRuntime(857): FATAL EXCEPTION: main
06-10 21:03:06.880: E/AndroidRuntime(857): Process: com.example.mapexample, PID: 857
06-10 21:03:06.880: E/AndroidRuntime(857): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapexample/com.example.mapexample.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.os.Handler.dispatchMessage(Handler.java:102)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.os.Looper.loop(Looper.java:136)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.ActivityThread.main(ActivityThread.java:5026)
06-10 21:03:06.880: E/AndroidRuntime(857):  at java.lang.reflect.Method.invokeNative(Native Method)
06-10 21:03:06.880: E/AndroidRuntime(857):  at java.lang.reflect.Method.invoke(Method.java:515)
06-10 21:03:06.880: E/AndroidRuntime(857):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
06-10 21:03:06.880: E/AndroidRuntime(857):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
06-10 21:03:06.880: E/AndroidRuntime(857):  at dalvik.system.NativeStart.main(Native Method)
06-10 21:03:06.880: E/AndroidRuntime(857): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-10 21:03:06.880: E/AndroidRuntime(857):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.Activity.setContentView(Activity.java:1930)
06-10 21:03:06.880: E/AndroidRuntime(857):  at com.example.mapexample.MainActivity.onCreate(MainActivity.java:15)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.Activity.performCreate(Activity.java:5242)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
06-10 21:03:06.880: E/AndroidRuntime(857):  ... 11 more
06-10 21:03:06.880: E/AndroidRuntime(857): 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
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.Fragment.instantiate(Fragment.java:597)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.Fragment.instantiate(Fragment.java:561)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.Activity.onCreateView(Activity.java:4788)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
06-10 21:03:06.880: E/AndroidRuntime(857):  ... 21 more
06-10 21:03:06.880: E/AndroidRuntime(857): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/com.example.mapexample-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.mapexample-1, /system/lib]]
06-10 21:03:06.880: E/AndroidRuntime(857):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
06-10 21:03:06.880: E/AndroidRuntime(857):  at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
06-10 21:03:06.880: E/AndroidRuntime(857):  at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
06-10 21:03:06.880: E/AndroidRuntime(857):  at android.app.Fragment.instantiate(Fragment.java:583)
06-10 21:03:06.880: E/AndroidRuntime(857):  ... 24 more

Copyright Notice:Content Author:「Kalyan Kumar」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30767104/android-google-maps-v2-stopping

Answers
Jayesh Elamgodil 2015-06-10T21:10:51

ClassNotFoundException, so mostly you have missed adding the library dependency. The Google Play Services need to be setup before using them into your project. Find details in the following link:\n\nhttps://developers.google.com/android/guides/setup\n\nAs per official documentation here https://developers.google.com/maps/documentation/android/start, the minimum required sdk version is 12. Please try increasing your minSdkVersion value to 12.",


More about “Android Google Maps v2 Stopping” related questions

Google Maps Api v2 Android Error

only Android 5.0 work. Error by Android 5.0 lower I have installed all SDK package. Manifest &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.an

Show Detail

Android Google Maps v2 Stopping

I am new to Android and Google Maps v2 API. I tried to integrate the API in my app but I am getting: Unfortunately, Map Example has stopped. Can anyone help me finding the mistake? MainActivity

Show Detail

Google android maps v2 MetersToEquatorPixel

I am currently tasked with converting a Google Android maps v1 application over to Google Android Maps V2 application. The process is not a pleasant one (thanks google). My problem is that in the

Show Detail

Google maps v2 on android emulator

I am facing an issue right now so i appeal to all you awesome android developers to help me out with this issue. There is a specific need in my application to run Google maps v2 on an emulator. Hav...

Show Detail

Google Maps Android API V2 not show maps on Emulator

I am following the tutorial to run Google Maps Android API V2. I am using an emulator. (I know a real device may solve the problem, but I do want to try emulator) The mapfragment shows a pale yellow

Show Detail

Open Street Maps with Android Google Maps Api v2

Is it possible to use an open street map provider with the new Google Maps V2 Api on Android? If so can you provide an example, or documentation? I have looked quickly at the docs and found

Show Detail

android google maps v2 in service

So i noticed that google maps for android has a v2. i was wondering if there is a difference between requestlocationupdate and setmylocationenabled. I want to create a service that requests user lo...

Show Detail

Comparing Google Maps v2 Screenshot in Android Test

I would like to compare 2 Google Maps v2 screenshots in Android test. Is there any advice where should I start? I've already used https://facebook.github.io/screenshot-tests-for-android/, but it s...

Show Detail

Using Google Maps Android v2 offline

I have an app to will sometimes get side loaded onto devices that will never have internet connectivity. I am already using google maps android v2 throughout the app and would like to continue usi...

Show Detail

Minimal Android API level to run Google Maps Android API v2

I have developed a mobile application that uses Google Maps Android API v1, and I plan to port it to the recent Google Maps Android API v2, as recommended by Google. However, my application also t...

Show Detail