저는 건물에있는 액티비티에 작은 MapFragment를 넣으려고하지만, 모든 작업을 수행하는 데 문제가 있습니다. Map API와 Play 서비스가 모두 제대로 설치되었다는 것을 알고 있습니다. 테스트 자습서를 작성하고 모든 것이 잘 작동했기 때문입니다.SupportMapFragment - Fragment에서 MapFragment로 캐스팅 할 수 없습니다.
문서 here에 따라 다음 문제가 발생합니다. 내 setUpMapIfNeeded 메서드에서 getFragmentManager()
또는 getSupportFragmentManager()
을 사용할 수 있습니다. getFragmentManager()
을 사용할 때 Eclipse는 멋지지만 실행하면 NoSuchMethodError
이라는 메서드가 정의되지 않았 음을 알게됩니다. 내가 getSupportFragmentManager()
을 선택할 때, Eclipse는 그것을 좋아하지 않고 "Fragment에서 MapFragment로 캐스트 할 수 없다"라는 오류를 내게줍니다. 그럼 거래는 뭐니? 어떤 제안?
private void setUpMapIfNeeded() {
//Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
mMap = ((MapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (mMap != null) {
//do things to the map
mMap.addMarker(new MarkerOptions().position(LOCATION).title(EXTRA_URL));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LOCATION,15));
mMap.getUiSettings().setZoomControlsEnabled(false);
}
}
}
내가 제공 할 수있는 다른 코드가 있으면 알려 주시면 신속하게 게시 해 드리겠습니다.
R.id.map에 class 속성이 있습니까? 'class = "com.google.android.gms.maps.MapFragment"' –