0

MainActivity onCreate:

    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.add(myItemizedOverlay); //List<OverlayItem> of myItemizedOverlay is empty

Later I add and remove items from myItemizedOverlay.

When List of myItemizedOverlay is empty and I click on the map then I get error.

How correctly organize this process?

chRyNaN
  • 3,592
  • 5
  • 46
  • 74
  • On form is 2 buttons : Add item, Remove item. During the process it can be the moment when myItemizedOverlay doesn't have items. – user1464440 Nov 03 '12 at 17:11

1 Answers1

0

I was faced with a similar problem once, or so I think. I allowed the user to save their location, which, I saved the locations to a file. Then when they viewed the map, I would load the contents of the file (the locations) and use an overlay to display the items on the map. However, if there were no items and the map was pressed I received an error.

If this is the problem you are facing as well, I solved the problem by placing a simple if statement.

When I get the locations from the file I would place each location into an arraylist, so, I used this if statement:

if (!fileList.isEmpty()){}

And I placed all the code to add the overlays within this if statement. I hope this helps!

chRyNaN
  • 3,592
  • 5
  • 46
  • 74
  • Thanks for answer. But maybe is it better way then add and remove whole myItemizedOverlay from mapView? – user1464440 Nov 03 '12 at 17:13
  • I'm not too sure what you mean. fileList is an arraylist, so when you hit the add button you can just use the method fileList.add(); and when you hit the remove button you could use the method fileList.remove(); That way, it will work and you won't receive an error when the list is empty as long as the code is within that if statement. – chRyNaN Nov 04 '12 at 04:06