Search code examples
androidoverlayosmdroid

OSMdroid - error: no suitable constructor found for Overlay(no arguments) constructor Overlay.Overlay(Context) is not applicable


While extending OSMdroid Overlay class in an application

import org.osmdroid.views.overlay.Overlay;
...
public class MapOverlayArea extends Overlay implements TextToSpeech.OnInitListener, OnTouchListener  {

...

I receive an error:

error: no suitable constructor found for Overlay(no arguments) constructor Overlay.Overlay(Context) is not applicable


Solution

  • As indicated by the error message, the required constructor was missing.

    public class MapOverlayArea extends Overlay implements TextToSpeech.OnInitListener, OnTouchListener  {
    
        public MapOverlayArea(Context ctx) {
            super(ctx);
        }
    
        //....
    }
    

    Including the constructor as above, and calling it correctly from main activity using

    MapOverlayArea mapOverlayArea = new MapOverlayArea(context);
    

    solves the problem.