0

I'm trying to use mapsforge to do a display maps on my phone.

Currently I'm having slight problems with regards to adding an overlay to display pins. This is the code that gives an error:

ArrayItemizedOverlay itemizedOverlay = new ArrayItemizedOverlay(defaultMarker, true);
myOpenMapView.getOverlays().add(itemizedOverlay);

getOverlays() will return List, as stated here

This line gives this error:

 "The method add(Overlay) in the type List<Overlay> is not applicable for the arguments (ArrayItemizedOverlay)"

which is what I don't really understand is why the .add() method is invalid in this case, since ArrayItemizedOverlay class is a subclass of the Overlay class.

These are the class definitions and I hope someone can enlighten me what I can do so that the .add() method will accept the object.

ArrayItemizedOverlay

public class ArrayItemizedOverlay extends ItemizedOverlay<OverlayItem> {
    //codes....
}

ItemizedOverlay

public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay {
    //codes...
}

Feel free to point out any missing information which you may need, thanks!

lyk
  • 1,578
  • 5
  • 25
  • 49
  • I type cast to an Overlay object and it doesn't work as well. Anyway I shouldn't be typecasting it or I will lose certain stuff from the sub class – lyk Mar 27 '13 at 10:20

2 Answers2

2

Were you able to find out the complete path of the calsses and interfaces used?

public List<Overlay> getOverlays()

returns a list of

public interface org.mapsforge.android.maps.overlay.Overlay

But the code base has a different overlay class

public abstract class Overlay extends Thread {

Is there an older version in the classpath? You probably have to cleanup the older JARs/APIs and make sure it refers to the correct overlay class.

gshank
  • 58
  • 2
  • 7
  • Sorry perhaps I might not be as clear as that. Overlay, ItemizedOverlay, ArrayItemizedOverlay and OverlayItem classes were from a previous version 0.3.0. These can be found here: https://code.google.com/p/mapsforge/source/browse/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/Overlay.java?name=0.3.0 – lyk Mar 27 '13 at 10:40
  • I think this is it. The `Overlay`s are not the same. – Vincent van der Weele Mar 27 '13 at 10:45
  • i have another Overlay class on my own, org.mapsforge.android.maps.old.overlay.Overlay. How do I change this then? in my MapView class where getOverlays() is, I have already imported org.mapsforge.android.maps.old.overlay.Overlay (which is the one I am using) – lyk Mar 27 '13 at 10:54
  • If your Overlay class satisfies all the dependencies in MapView, you can import the abstract Overlay class in your MapView. This means you are modifying the source and will face problems during upgrade. Either switch to the older version of MapView or better option is not to use the older version, upgrade to the latest and modify your code usage to use the latest APIs. – gshank Mar 27 '13 at 11:17
  • I would have loved to use the newest version. Problem is, their latest version does not support the usage of Overlays to add pins at all, which is why my project library has a hybrid of the new and old classes. Thanks for the heads up anyway, I will look into detail what I might have missed out again – lyk Mar 27 '13 at 11:24
0

Use the method addAll() of List to add a Collection of Object.

Lionel Père
  • 526
  • 2
  • 5
  • 17
  • ????????? I'm adding ONE object, not a collection of objects. But doesn't matter, I did addAll() and I'm still getting the same problem – lyk Mar 27 '13 at 10:26