SupportMapFragment 始终为空
SupportMapFragment always null
我看到很多关于这个的问题,但我没有找到任何解决我问题的答案,这是我的 class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.mapa, container, false);
SupportMapFragment fm = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
MarkerOptions options = new MarkerOptions();
options.position(LOWER_MANHATTAN);
options.position(BROOKLYN_BRIDGE);
options.position(WALL_STREET);
googleMap.addMarker(options);
String url = getMapsApiDirectionsUrl();
ReadTask downloadTask = new ReadTask();
downloadTask.execute(url);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(BROOKLYN_BRIDGE,
13));
addMarkers();
return v;
}
我的布局是这样的:
<com.google.android.gms.maps.MapView
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" />
我有这个错误
Process: PID: 4701
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap
com.google.android.gms.maps.SupportMapFragment.getMap()' on a null
object reference
at greetrack.estg.ipvc.greentrack.Mapa.onCreateView(Mapa.java:96)
我知道我的错误在于 returns null 但我不知道怎么办...
and my layout is this
在该布局中,将 com.google.android.gms.maps.MapView
替换为 fragment
。要在布局资源中嵌入静态片段,您可以使用 <fragment>
元素。
我看到很多关于这个的问题,但我没有找到任何解决我问题的答案,这是我的 class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.mapa, container, false);
SupportMapFragment fm = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
MarkerOptions options = new MarkerOptions();
options.position(LOWER_MANHATTAN);
options.position(BROOKLYN_BRIDGE);
options.position(WALL_STREET);
googleMap.addMarker(options);
String url = getMapsApiDirectionsUrl();
ReadTask downloadTask = new ReadTask();
downloadTask.execute(url);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(BROOKLYN_BRIDGE,
13));
addMarkers();
return v;
}
我的布局是这样的:
<com.google.android.gms.maps.MapView
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" />
我有这个错误
Process: PID: 4701 java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.SupportMapFragment.getMap()' on a null object reference at greetrack.estg.ipvc.greentrack.Mapa.onCreateView(Mapa.java:96)
我知道我的错误在于 returns null 但我不知道怎么办...
and my layout is this
在该布局中,将 com.google.android.gms.maps.MapView
替换为 fragment
。要在布局资源中嵌入静态片段,您可以使用 <fragment>
元素。