Home Ask Login Register

Developers Planet

Your answer is one click away!

Umer Asif February 2016

Unknown Source when adding a Circle in Google Maps V2

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 andr        

Answers


Aliyu Abdullahi February 2016

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


Umer Asif February 2016

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

Post Status

Asked in February 2016
Viewed 2,959 times
Voted 12
Answered 2 times

Search




Leave an answer


Quote of the day: live life