1

I have a map on which i am adding Markers and circle around it but when i try to add circle it gives a nullpointerEcxeption, I don't know what is causing it. I can add marker's and map is being shown correctly.

      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();

                }
            }
        });

Here is my 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)

Here is my googleMap setup.

      @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);
}}
Umer Asif
  • 441
  • 1
  • 4
  • 15

2 Answers2

1

The map is not loaded, did you add this line of code to setup your map? SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager () .findFragmentById (R.id.map); mapFragment.getMapAsync (this); to sync your map. If you don't sync the map, you will have Unknown source issue. Look at this tutorial from tutorial point on how to use google map http://www.tutorialspoint.com/android/android_google_maps.htm Hope this help

Aliyu Abdullahi
  • 129
  • 1
  • 4
1

Turns out I was missing center of the circle. Thanks Daniel.

Umer Asif
  • 441
  • 1
  • 4
  • 15