INTRODUCTION
For my app, I need to manage the orientation due to I'm working with fragments. In portrait mode, I start GoogleMapsFragment in a new Activity. But in landscape mode, I start GoogleMapsFragment at the right side of main Activity.
Have to say that in protrait mode everything wortks fine. I call GoogleMapsFragment and Maps starts on a new Activity.
PROBLEM
But in landscape mode, when I start GoogleMapsFragment, throws me a NullPointerException and gets out of the app.
This is a snippet of code of GoogleMapsFragment:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mainView = inflater.inflate(R.layout.google_maps, container, false);
mMapView = (MapView) mainView.findViewById(R.id.map_view);
mMapView.onCreate(savedInstanceState);
mMap = mMapView.getMap();
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.setMyLocationEnabled(true);
//...
Where I'm getting the null is when I do mMap = mMapView.getMap()
, it seems that it isn't returning any value to mMap, so in the next step, as mMap is null, it throws the exception.
This is the layout "google_maps.xml":
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
I don't know why is working in portrait mode but no in landscape mode. Also have to say that the portrait mode has been tested on a real device, and landscape mode in the emulator, maybe this could be the cause...
If this is the reason, how could I test it?
UPDATE --
Using Google API 4.4.2 on the emulator, this continues the NullPointerException issue but this is what the LogCat also shows:
Google Play services out of date. Requires 4132500 but found 4033530