I imported google_play_services_lib from the Eclipse extras into my Workspace. I created a new Android Project and included google_play_services_lib as a library. My Project has android-support-v4.jar and google-play-services.jar
Now My Manifest file:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- add for map2 -->
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY API NUMBER" />
<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="com.phanism.gingerbreadmaps.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>
</application>
</manifest>
My activity_main is:
package com.phanism.gingerbreadmaps;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMap().setMyLocationEnabled(true);
}
}
And my layout file is :
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.phanism.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
When I compile the above code, in emulator, I am being asked to update the Google Play Store. When I press OK, I am getting this error. On a Device, I my App is crashing directly and when I look at the Debugging, this is the error I am getting.
12-03 08:43:06.851: E/AndroidRuntime(620): FATAL EXCEPTION: main
12-03 08:43:06.851: E/AndroidRuntime(620): java.lang.NullPointerException
12-03 08:43:06.851: E/AndroidRuntime(620): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1409)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.app.Activity.startActivityForResult(Activity.java:3351)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.app.Activity.startActivityForResult(Activity.java:3312)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:824)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.app.Activity.startActivity(Activity.java:3522)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.app.Activity.startActivity(Activity.java:3490)
12-03 08:43:06.851: E/AndroidRuntime(620): at com.google.android.gms.dynamic.a$5.onClick(Unknown Source)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.view.View.performClick(View.java:4084)
12-3 08:43:06.851: E/AndroidRuntime(620): at android.view.View$PerformClick.run(View.java:16966)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.os.Handler.handleCallback(Handler.java:615)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.os.Handler.dispatchMessage(Handler.java:92)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.os.Looper.loop(Looper.java:137)
12-03 08:43:06.851: E/AndroidRuntime(620): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-03 08:43:06.851: E/AndroidRuntime(620): at java.lang.reflect.Method.invokeNative(Native Method)
12-03 08:43:06.851: E/AndroidRuntime(620): at java.lang.reflect.Method.invoke(Method.java:511)
12-03 08:43:06.851: E/AndroidRuntime(620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-03 08:43:06.851: E/AndroidRuntime(620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-03 08:43:06.851: E/AndroidRuntime(620): at dalvik.system.NativeStart.main(Native Method)
Can anyone point out to me what I am doing wrong.
Add this in your manifest file :
Hope this helps.