gpt4 book ai didi

java - 为什么错误 CameraUpdateFactory 未在 MapsFragment android 中初始化?

转载 作者:行者123 更新时间:2023-11-30 01:51:44 25 4
gpt4 key购买 nike

我想在 map 上显示一些点,但是当我在 map 上设置相机时为什么会出现这个错误?如果顺序 CameraUpdateFactory 程序出现问题,以前我没有遇到错误

java.lang.RuntimeException:无法启动 Activity ComponentInfo{com.bongkorr/com.hospifinder.Maps}:java.lang.NullPointerException:CameraUpdateFactory 未初始化

完整的是 CameraUpdateFactory 的草稿代码,这有什么问题吗?

map .java

public class Maps<Passing> extends FragmentActivity implements LocationListener {

private GoogleMap map;
private DBAdapter dbhelper;
private SQLiteDatabase db = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbhelper = new DBAdapter(this);
db = dbhelper.getWritableDatabase();
dbhelper.delAllData(db);
//dbhelper.delAllData2(db);
dbhelper.generateDataLokasi(db);
dbhelper.generateDataRS(db);
setContentView(R.layout.maps);



SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = fm.getMap();

map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-6.604345,
106.796640), 12));

map.setMyLocationEnabled(true);

Cursor c = dbhelper.fetchAllLokasi(db);
int col = dbhelper.fetchAllLokasi(db).getCount();




if (col == 0) {
Toast.makeText(Maps.this, "Pas de donnees ", Toast.LENGTH_LONG)
.show();

} else {

c.moveToFirst();
while (c.isAfterLast() == false) {

String id = "" + c.getInt(0);
String nama = c.getString(1);
String longitude = c.getString(3);
String latitude = c.getString(2);
String ket = c.getString(4);


Marker marker = map.addMarker(new MarkerOptions()
.position(
new LatLng(Double.parseDouble(latitude), Double
.parseDouble(longitude)))
.title(nama)
.snippet(ket)

.icon(BitmapDescriptorFactory
.fromResource(R.drawable.icmarker)));
c.moveToNext();



}
}

我没有找到这个答案,我多次运行这个应用程序,修复了错误,如果我的代码有问题?请帮忙

最佳答案

我认为您需要显式调用 MapsInitializer

示例代码:

@Override public View 
onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.map_panel, container, false);
mapView = (MapView) view.findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
configureMap(mapView.getMap());
return view;
}

private void
configureMap(GoogleMap map, double lat, double lon)
{
if (map == null)
return; // Google Maps not available
try {
MapsInitializer.initialize(getActivity());
}
catch (GooglePlayServicesNotAvailableException e) {
Log.e(LOG_TAG, "Have GoogleMap but then error", e);
return;
}
map.setMyLocationEnabled(true);
LatLng latLng = new LatLng(lat, lon);
CameraUpdate camera = CameraUpdateFactory.newLatLng(latLng);
map.animateCamera(camera);
}

关于java - 为什么错误 CameraUpdateFactory 未在 MapsFragment android 中初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32939981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com