I have this problem when implementing a MapView on a fragment
public class UbicacionMiEmpresa extends Fragment implements OnMapReadyCallback{
MapView mapView;
GoogleMap mGoogleMap;
View vista;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
vista = inflater.inflate(R.layout.fragment_ubicacion_mi_empresa, container, false);
return vista;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mapView = (MapView) vista.findViewById(R.id.map_view);
if(mapView != null){
mapView.onCreate(null);
mapView.onResume();
mapView.getMapAsync(this);
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
MapsInitializer.initialize(getContext());
mGoogleMap = googleMap;
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(40.689247, -74.044502)));
CameraPosition Library = CameraPosition.builder().target(new LatLng(40.689247, -74.044502)).zoom(16).bearing(0).tilt(0).build();
mGoogleMap.moveCamera(CameraUpdateFactory.newCameraPosition(Library));
}
}
My fragment layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MiEmpresa.UbicacionMiEmpresa">
<!-- TODO: Update blank fragment layout -->
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="278dp"
android:layout_height="297dp"
/>
</RelativeLayout>
Error when debugging
Process: mx.emy.emymexico, PID: 9394 java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.inputmethod.InputConnection.closeConnection () 'on a null object reference at android.view.inputmethod.InputConnectionWrapper.closeConnection (InputConnectionWrapper.java:270) at com.android.internal.view.IInputConnectionWrapper.executeMessage (IInputConnectionWrapper.java:541) at com.android.internal.view.IInputConnectionWrapper $ MyHandler.handleMessage (IInputConnectionWrapper.java:85) at android.os.Handler.dispatchMessage (Handler.java:105) at android.os.Looper.loop (Looper.java:164) at android.app.ActivityThread.main (ActivityThread.java:6592) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.Zygote $ MethodAndArgsCaller.run (Zygote.java:240) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:769)