1

我正在尝试让我的地图缩放到给定的边界。但我得到一个错误。

这是我的代码

   @Override
     public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       try {
           MapsInitializer.initialize(this);
       } catch (GooglePlayServicesNotAvailableException e) {
           e.printStackTrace();
       }

       mapFragment = new SupportMapFragment();

       FragmentManager fragmentManager = getSupportFragmentManager();
       FragmentTransaction transaction = fragmentManager.beginTransaction();
       transaction.replace(R.id.map, mapFragment);
       transaction.commit();
       mMap = mapFragment.getMap();


       LatLngBounds boundsBucuresti = new LatLngBounds;

       mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(boundsBucuresti, 20));

和错误:

01-12 19:52:53.077: ERROR/AndroidRuntime(13173): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.mobileit.android.transport_noapte/com.mobileit.android.transport_noapte.M    yActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
        at android.app.ActivityThread.access$1500(ActivityThread.java:123)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3835)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at com.mobileit.android.transport_noapte.MyActivity.onCreate(MyActivity.java:42)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
        ... 11 more

(MyActivity.java:42)指的是这个

mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(boundsBucuresti, 20));

4

0 回答 0