JackD JackD - 5 months ago 29
Android Question

Cannot resolve method 'super()' error in android studio

I am getting the error: "Cannot resolve method 'super()'" in my code and I am not sure how to resolve this, do you have any clues?

The code is as follows:

public GeoView( double left, double top, double width )
{
super();

this.left = left;
this.top = top;
this.width = width;

this.transform = null;
this.backing_store = null;

this.sink = false;

this.last_size = new Rect(0, 0, 200, 200 );
this.do_tracking = false;

Drawable background = new Drawable() {
@Override
public void draw(Canvas canvas) {

}

@Override
public void setAlpha(int i) {

}

@Override
public void setColorFilter(ColorFilter colorFilter) {

}

@Override
public int getOpacity() {
return 0;
}
};

Answer

What is GeoView class? You extended it from another class? If yes. Check that parent class have empty constructor, because you call it.
If it's your own class and it didn't extended from any other class. Then you don't need to call super().

View doesn't have empty constructor. You should Have at list one of this constructor.

    public GeoView(Context context) {
        super(context);
    }

    public GeoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public GeoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

If you want to create view by yourself, you need first constructor. Then you have to

GeoView geoView = new GeoView(YourActivity.this);

Or you can simply ass your view to layout. Then You second will be called constructor. I think you should add all of them.

<com.example.yourapp.GeoView
    android:layout_height="300dp"
    android:layout_width="match_parent"/>