我有一张地图,我在其上添加了标记并围绕它循环但是当我尝试添加圆圈时它会给出一个nullpointerEcxeption,我不知道是什么导致它。我可以添加标记并正确显示地图。
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (name.getText() == null || radius.getText() == null) {
Toast.makeText(getContext(), "Name and Radius Please", Toast.LENGTH_SHORT).show();
} else {
CircleOptions c = new CircleOptions().strokeColor(Color.BLUE).radius(Integer.parseInt(radius.getText().toString())); This is the line where it happens
**googlemap.addCircle(c);**
DataBaseOperations hell = new DataBaseOperations(getContext());
SQLiteDatabase db = hell.getWritableDatabase();
hell.SaveMarker(name.getText().toString(),c.getRadius(),marker.getId(),latLng,db);
item.setVisibility(View.INVISIBLE);
hell.close();
db.close();
}
}
});
这是我的Stack
java.lang.NullPointerException
at com.google.a.a.ae.a(Unknown Source)
at com.google.maps.api.android.lib6.e.eg.<init>(Unknown Source)
at com.google.maps.api.android.lib6.e.ev.a(Unknown Source)
at com.google.android.gms.maps.internal.j.onTransact(SourceFile:390)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addCircle(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addCircle(Unknown Source)
at com.example.umerasif.homealarm.Map$3.onClick(Map.java:160)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
这是我的googleMap设置。
@Override
public void onMapReady(GoogleMap googleMap) {
setmap(googleMap);
}
public void setmap(final GoogleMap map) {
googlemap = map;
if(googlemap != null){
if (sharedPreferences.getBoolean(CustomAlarm.satellite, false)) {
googlemap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
} else {
googlemap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
googlemap.getUiSettings().setScrollGesturesEnabled(true);
googlemap.setOnMapLongClickListener(this);
googlemap.setLocationSource(new com.example.umerasif.homealarm.LocationSource(getContext(), googlemap));
MapStateListener mapStateListener = new MapStateListener(googlemap, app_touchableMapFragment, getActivity(), pager);
mapStateListener.setStateListener(this);
}}
答案 0 :(得分:1)
未加载地图,您是否添加了这行代码来设置地图? SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); 同步您的地图。如果您不同步地图,则会出现“未知来源”问题。从教程点了解如何使用谷歌地图的本教程 http://www.tutorialspoint.com/android/android_google_maps.htm 希望这个帮助
答案 1 :(得分:1)
原来我错过了圆圈的中心。谢谢Daniel。