0


I'm trying to get the Google Maps API v2 working for a project. I've downloaded the latest version of the Google Play Services via the Android SDK Manager and imported the Google Play services as an library project into Eclipse.
I've also added a reference to the library project via Project->Properties->Android->Library for my app.


My project to test the Google Maps API has only a MainActivity and the associated layout file.

MainActivity.java

package com.example.googlemapstest;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity
{

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

        if (savedInstanceState != null)
        {
            return;
        }
        getSupportFragmentManager().beginTransaction()
            .add(R.id.fragment_container, new SupportMapFragment()).addToBackStack(null).commit();
    }
}

activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapstest"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <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" >
        <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>

        <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="my key" />
    </application>

</manifest>

LogCat stackTrace

08-27 14:26:22.138: E/dalvikvm(3408): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.example.googlemapstest.MainActivity.onCreate
08-27 14:26:22.138: W/dalvikvm(3408): VFY: unable to resolve new-instance 922 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/example/googlemapstest/MainActivity;
08-27 14:26:22.428: W/dalvikvm(3408): threadid=1: thread exiting with uncaught exception (group=0x41332a08)
08-27 14:26:22.433: E/AndroidRuntime(3408): FATAL EXCEPTION: main
08-27 14:26:22.433: E/AndroidRuntime(3408): java.lang.NoClassDefFoundError: com.google.android.gms.maps.SupportMapFragment
08-27 14:26:22.433: E/AndroidRuntime(3408):     at com.example.googlemapstest.MainActivity.onCreate(MainActivity.java:22)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.app.Activity.performCreate(Activity.java:5165)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1103)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2419)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.app.ActivityThread.access$600(ActivityThread.java:162)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.os.Looper.loop(Looper.java:158)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at android.app.ActivityThread.main(ActivityThread.java:5751)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at java.lang.reflect.Method.invokeNative(Native Method)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at java.lang.reflect.Method.invoke(Method.java:511)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
08-27 14:26:22.433: E/AndroidRuntime(3408):     at dalvik.system.NativeStart.main(Native Method)

I've already reinstalled the library. The ADT and the SDK have both the latest versions. I've also looked at existing threads with the same problem, but none of them has an answer which works (e.g. Error java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in Google Map V2)

Regards,
BrickTop

Community
  • 1
  • 1
BrickTop
  • 230
  • 2
  • 9

0 Answers0