Skip to content

Instantly share code, notes, and snippets.

@progzilla
Last active August 26, 2015 10:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save progzilla/b279b625599dace0453d to your computer and use it in GitHub Desktop.
Android MapView NullPointerException
public class MainMapView extends FrameLayout {
@InjectView(R.id.map) MapView mapView;
public MainMapView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
inflate(getContext(), R.layout.discount_map_content, this);
ButterKnife.inject(this);
}
public void onCreate(Bundle savedInstanceState) {
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
mapView.getMap().getUiSettings().setMyLocationButtonEnabled(false);
mapView.getMap().setMyLocationEnabled(true);
// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
MapsInitializer.initialize(getContext());
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(Position.getCurrent(getContext()).toLatLng(), 14);
mapView.getMap().moveCamera(cameraUpdate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment