我的Erros log cat
06-03 23:28:48.961: E/ViewRootImpl(4527): sendUserActionEvent() mView == null
06-03 23:28:54.491: E/AndroidRuntime(4527): FATAL EXCEPTION: main
06-03 23:28:54.491: E/AndroidRuntime(4527): java.lang.NullPointerException
06-03 23:28:54.491: E/AndroidRuntime(4527): at nir.rauch.flantir.MainActivity$1.onMyLocationButtonClick(MainActivity.java:58)
06-03 23:28:54.491: E/AndroidRuntime(4527): at com.google.android.gms.maps.GoogleMap$2.onMyLocationButtonClick(Unknown Source)
06-03 23:28:54.491: E/AndroidRuntime(4527): at com.google.android.gms.maps.internal.m$a.onTransact(Unknown Source)
06-03 23:28:54.491: E/AndroidRuntime(4527): at android.os.Binder.transact(Binder.java:347)
06-03 23:28:54.491: E/AndroidRuntime(4527): at foj.a(SourceFile:81)
06-03 23:28:54.491: E/AndroidRuntime(4527): at lxw.onClick(Unknown Source)
06-03 23:28:54.491: E/AndroidRuntime(4527): at android.view.View.performClick(View.java:4475)
06-03 23:28:54.491: E/AndroidRuntime(4527): at android.view.View$PerformClick.run(View.java:18786)
06-03 23:28:54.491: E/AndroidRuntime(4527): at android.os.Handler.handleCallback(Handler.java:730)
06-03 23:28:54.491: E/AndroidRuntime(4527): at android.os.Handler.dispatchMessage(Handler.java:92)
06-03 23:28:54.491: E/AndroidRuntime(4527): at android.os.Looper.loop(Looper.java:137)
06-03 23:28:54.491: E/AndroidRuntime(4527): at android.app.ActivityThread.main(ActivityThread.java:5419)
06-03 23:28:54.491: E/AndroidRuntime(4527): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 23:28:54.491: E/AndroidRuntime(4527): at java.lang.reflect.Method.invoke(Method.java:525)
06-03 23:28:54.491: E/AndroidRuntime(4527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
06-03 23:28:54.491: E/AndroidRuntime(4527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
06-03 23:28:54.491: E/AndroidRuntime(4527): at dalvik.system.NativeStart.main(Native Method)
我的活动中崩溃的部分:
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Criteria;
import android.location.LocationManager;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
public class MainActivity extends Activity {
public GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmap);
final GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
final android.location.Location location = locationManager
.getLastKnownLocation(locationManager.getBestProvider(criteria,
false));
if (location != null) {
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
location.getLatitude(), location.getLongitude()), 10));
}
map.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
if (!locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
buildAlertMessageNoGps();
} else {
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(),location.getLongitude()), 15));
return false;
}
return false;
}
});
}