gpt4 book ai didi

java.lang.NullPointerException :com. 谷歌.android.gms.maps.GoogleMap.moveCamera

转载 作者:搜寻专家 更新时间:2023-11-01 08:05:43 27 4
gpt4 key购买 nike

我目前正在研究新的 Google Maps Android API v2。

我的 MapActivity 类使用下面的代码与我的三星 galaxy s3 ans s2 一起工作:

但是,有一些特定的设备不​​工作,例如:GT-S5830i

class MapActivity extends FragmentActivity  implements OnMapClickListener, OnMapLongClickListener, OnMarkerClickListener
{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);

tvLocInfo = (TextView)findViewById(R.id.locinfo);

android.support.v4.app.FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment myMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = myMapFragment.getMap();

myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
ArrayList<Cooridnates> cooridnatesList = MainActivity.getList();
for(int i=0;i<cooridnatesList.size();i++)
{
//Toast.makeText(MapActivity.this, "SIZE : " + " " + cooridnatesList.size(), Toast.LENGTH_LONG).show();
LatLng point = new LatLng(cooridnatesList.get(i).getLat(),cooridnatesList.get(i).getLon());
tvLocInfo.setText("markers added");
myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
center=CameraUpdateFactory.newLatLng(point);
}

CameraUpdate zoom=CameraUpdateFactory.zoomTo(16);
myMap.moveCamera(center);
myMap.animateCamera(zoom);
myMap.setOnMapClickListener(this);
myMap.setOnMarkerClickListener(this);
markerClicked = false;
}

出于某种原因,我收到此错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.coldice.plotfinder/com.coldice.plotfinder.MapActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.google.android.gms.maps.GoogleMap.moveCamera(Unknown Source)
at com.coldice.plotfinder.MapActivity.onCreate(MapActivity.java:70)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more

最佳答案

您的函数 MainActivity.getList() 可能返回了一个空列表,因此 for 循环不会执行 center=CameraUpdateFactory.newLatLng(point);

关于java.lang.NullPointerException :com. 谷歌.android.gms.maps.GoogleMap.moveCamera,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14551478/

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