dontHaveName
dontHaveName

Reputation: 1937

android @Override error before function

I am having this error:

@Override
public void paint(Canvas canvas) {
}

The method paint(Canvas) of type MainActivity must override or implement a supertype method. The error disappears only if I remove the @Override before the method. I have already set in project properties java compiler on level 1.6

Can you help me?

Upvotes: 2

Views: 1068

Answers (3)

laurentiugh
laurentiugh

Reputation: 83

if indeed the method that you want to override exists in the parent class then make sure you are compiling with at least java 1.6

So left click on your project -> properties -> Java Compiler -> Select at least java 1.6 then clean the project and rebuild.

Upvotes: 0

amit
amit

Reputation: 178431

It seems you are trying to override a method that doesn't "exist" in MainActivity's superclass.

Some possible reasons (and solutions):

  1. You forgot to add extends ... to the class you think it (MainActivity) inherits from.
  2. You confused the method name, and it shouldn't be paint() - if this is the case - just change the method name
  3. It is a new method for this class - and the annotation @Override should be deleted.
  4. You changed the arguments for the original method - and you are overloading instead of overriding. You should stick with the same arguments if you really want to override it, or remove the @Override annotation if you are after overloading.

Upvotes: 1

Tiago Almeida
Tiago Almeida

Reputation: 14237

If you are extending an Activity you can't override the paint method.

Paint is not an Activity method. You can only override existent methods from the class you are extending.

Also I never used Paint. Did you want to override the onDraw(Canvas) from the View?

Upvotes: 3

Related Questions