I follow steps for configure Google Maps Android API v2 Official steps
I am using Android 3.1 version.
I am getting error which I run project.
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.mapdemo.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.example.mapdemo.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="I paste my key as shown in picture"/>
</application>
</manifest>
MainActivity.java
package com.example.mapdemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
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"
class="com.google.android.gms.maps.MapFragment"/>
LogCat
01-20 15:00:18.325: E/dalvikvm(856): Could not find class 'com.google.android.gms.maps.model.LatLng', referenced from method com.google_map.MainActivity.<clinit>
01-20 15:00:18.395: E/dalvikvm(856): Could not find class 'com.google.android.gms.maps.MapFragment', referenced from method com.google_map.MainActivity.onCreate
01-20 15:00:18.565: E/AndroidRuntime(856): FATAL EXCEPTION: main
01-20 15:00:18.565: E/AndroidRuntime(856): java.lang.ExceptionInInitializerError
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.Class.newInstanceImpl(Native Method)
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.Class.newInstance(Class.java:1301)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1663)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.os.Looper.loop(Looper.java:132)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.main(ActivityThread.java:4025)
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.reflect.Method.invoke(Method.java:491)
01-20 15:00:18.565: E/AndroidRuntime(856): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-20 15:00:18.565: E/AndroidRuntime(856): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-20 15:00:18.565: E/AndroidRuntime(856): at dalvik.system.NativeStart.main(Native Method)
01-20 15:00:18.565: E/AndroidRuntime(856): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.maps.model.LatLng
01-20 15:00:18.565: E/AndroidRuntime(856): at com.google_map.MainActivity.<clinit>(MainActivity.java:32)
01-20 15:00:18.565: E/AndroidRuntime(856): ... 15 more
I also want to know minimum requirement for Google map API v2
First install Google play service and if you are using Android 2.2 then use this code
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With