2016-04-07 37 views
-1

başlatmak çalışırken bu hatayı alıyorum. Bu neden oluyor? Etkinliğimi AppCompatActivity yerine FragmentActivity uzanır çünkü NullPointerException SupportMapFragment

bu eğer evet sonra ben nasıl uygulayabileceğiniz mümkün olabilir GMaps Eğer xml ve java SupportMapFragment almaya çalışırken MapFragment kullandık Çünkü

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> 

cevap

0

AppCompatActivity içinde. Eğer MapFragment kullanmak istiyorsanız o zaman SupportMapFragment kullanmak istiyorsanız o zaman bu

<fragment 
    android:id="@+id/hotel" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/hotelLabel" /> 
için

<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" /> 

değiştirmek Veya

MapFragment mapHotelFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.hotel); 

ile

SupportMapFragment mapHotelFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.hotel); 

yerine Yani

İlgili konular