I use eclipse and android sdk.I want to pin point a location on map so i use this function when user click on a button:
public void pinpointlocation(Context context){
map = ((SupportMapFragment) ((FragmentActivity) mContext).getSupportFragmentManager().findFragmentById(android.R.id.content))
.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);
}
but when i run the program in emulator it crash and get me these error :
04-24 06:16:35.327: E/AndroidRuntime(4070): java.lang.NullPointerException
04-24 06:16:35.327: E/AndroidRuntime(4070): at com.example.hach.Mhelper.pinpointlocation(Mhelper.java:59)
04-24 06:16:35.327: E/AndroidRuntime(4070): at com.example.hach.MainActivity$PlaceholderFragment$1.onClick(MainActivity.java:90)
which line 59 is the first line of the function. Why the map is null?