Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么在MapsFragment android中未初始化错误CameraUpdateFactory?_Java_Android_Eclipse_Google Maps_Google Maps Android Api 2 - Fatal编程技术网

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

Java 为什么在MapsFragment android中未初始化错误CameraUpdateFactory?,java,android,eclipse,google-maps,google-maps-android-api-2,Java,Android,Eclipse,Google Maps,Google Maps Android Api 2,我想在地图上显示一些点,但当我在地图上设置相机时,为什么会发生此错误?如果order CameraUpdateFactory程序出现错误,以前我没有遇到错误 java.lang.RuntimeException:无法启动活动组件信息{com.bongkorr/com.hospifinder.Maps}:java.lang.NullPointerException:CameraUpdateFactory未初始化 完整是CameraUpdateFactory的草稿代码,这有什么问题吗 Maps.ja

我想在地图上显示一些点,但当我在地图上设置相机时,为什么会发生此错误?如果order CameraUpdateFactory程序出现错误,以前我没有遇到错误

java.lang.RuntimeException:无法启动活动组件信息{com.bongkorr/com.hospifinder.Maps}:java.lang.NullPointerException:CameraUpdateFactory未初始化

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

Maps.java
公共类映射扩展FragmentActivity实现LocationListener{
私人谷歌地图;
专用数据库适配器数据库助手;
私有SQLiteDatabase db=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
dbhelper=新的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();
地图。移动摄像头(摄像头更新工厂。新车床空间(新车床(-6.604345,
106.796640), 12));
map.setMyLocationEnabled(true);
游标c=dbhelper.fetchAllLokasi(db);
int col=dbhelper.fetchAllLokasi(db.getCount();
如果(列==0){
Toast.makeText(Maps.this,“Pas de donnees”,Toast.LENGTH\u LONG)
.show();
}否则{
c、 moveToFirst();
while(c.isAfterLast()==false){
字符串id=“”+c.getInt(0);
字符串nama=c.getString(1);
字符串经度=c.getString(3);
字符串纬度=c.getString(2);
String ket=c.getString(4);
Marker Marker=map.addMarker(新MarkerOptions()
.职位(
新LatLng(双精度、双精度(纬度)、双精度
.parseDouble(经度)))
.标题(非农产品市场准入)
.代码段(ket)
.图标(位图描述符工厂)
.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);
}
@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);
}