Ich erhalte diesen Fehler zu initialisieren versuchen:Nullpointer wenn SupportMapFragment
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference
Da mapHotelFragment bleiben immer null obwohl das Fragment existiert in Layout. Warum passiert dies?
Kann das möglich sein, weil meine Tätigkeit AppCompatActivity
statt FragmentActivity
wenn sich ja dann, wie ich GMaps
in AppCompatActivity
public class CheckinActivity extends AppCompatActivity implements OnMapReadyCallback {
…
SupportMapFragment mapHotelFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.hotel);
mapHotelFragment.getMapAsync(this);
…
@Override
public void onMapReady(GoogleMap googleMap) {
mapEventLocation = googleMap;...
}
…
<LinearLayout
android:id="@+id/hotelMap"
android:layout_width="match_parent"
android:layout_height="@dimen/tile_height"
android:orientation="vertical">
<fragment
android:id="@+id/hotel"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/hotelLabel" />
</LinearLayout>
</RelativeLayout>