I'm new to android development but am still learning and have created a few apps of simple activities. But this app which needs me to have a google map service activity can't be executed by me. Please review the codes and explain any error. I'd be very thankful to you.
Here's the Manifest code
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<permission
android:name="com.example.googlemaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" >
<activity
android:name="in.csbuddy.aaas.Aaas"
android:label="@string/app_name" >
<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.maps.v2.API_KEY"
android:value="AIzaSyAJJlKWPyQmwjfua1HV0fVHVkbN4Ny_iaw" />
</application>
And the java code
package in.csbuddy.aaas;
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 Aaas 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.layout_aaas);
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.aaas, menu);
return true;
}
}
and the layout file is as follows:
<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>
LOGCAT:
04-11 00:26:32.997: E/AndroidRuntime(22852): FATAL EXCEPTION: main
04-11 00:26:32.997: E/AndroidRuntime(22852): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Activity.onCreateView(Activity.java:4745)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:271)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Activity.setContentView(Activity.java:1895)
04-11 00:26:32.997: E/AndroidRuntime(22852): at in.csbuddy.aaas.Aaas.onCreate(Aaas.java:23)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Activity.performCreate(Activity.java:5133)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2311)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.access$600(ActivityThread.java:149)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.os.Looper.loop(Looper.java:137)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.main(ActivityThread.java:5214)
04-11 00:26:32.997: E/AndroidRuntime(22852): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 00:26:32.997: E/AndroidRuntime(22852): at java.lang.reflect.Method.invoke(Method.java:525)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
04-11 00:26:32.997: E/AndroidRuntime(22852): at dalvik.system.NativeStart.main(Native Method)
04-11 00:26:32.997: W/ActivityManager(842): Force finishing activity in.csbuddy.aaas/.Aaas
Everytime I try to run, the app won't open and show the "Unfortunately.." error. Please help me.