我正在尝试将Google地图实施为一个片段,但我收到的错误告诉我,我无法在此行解析我的inflater或容器:
rootview = inflater.inflate(R.layout.menu1_layout, container, false);
。
这可能与我的布局文件有关吗?这是我的Java片段:
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class menu_1_fragment extends Fragment implements OnMapReadyCallback {
View rootview;
@Nullable
@Override
protected View onCreateView(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
rootview = inflater.inflate(R.layout.menu2_layout, container, false);
return rootview;
}
@Override
public void onMapReady(GoogleMap map) {
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
}
答案 0 :(得分:1)
从以下方式更改您的方法:
protected View onCreateView(Bundle savedInstanceState)
到
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
也 删除超级电话