This works on api 12 and above but on 11 and below crash.
This is my class:
public class Home extends Fragment {
SupportMapFragment mMapView;
GoogleMap googleMap;
final long tiempo = 5 * 1000;
double latitude,longitude;
public View view;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null)
parent.removeView(view);
}
try {
view = inflater.inflate(R.layout.fragment_home, container, false);
} catch (InflateException e) {
}
GPSTracker gps = new GPSTracker(getActivity());
if(gps.canGetLocation()){
latitude = gps.getLatitude();
longitude = gps.getLongitude();
mMapView = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapa);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();// needed to get the map to display immediately
googleMap = mMapView.getMap();
}else{
gps.showSettingsAlert();
}
return view;
}
}
THIS my XML
<com.google.android.gms.maps.SupportMapFragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapa"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This is the error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{.MainActivity}: java.lang.NullPointerException