使用的代码是这样的:
private GoogleMap mMap;
MapFragment mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.rl_map, mMapFragment);
fragmentTransaction.commit();
mMap = mMapFragment.getMap();
它显示了相对布局(R.id.rl_map)内的地图,但是当我尝试将标记放在:
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Hello world"));
它给出了空指针异常