javaandroideclipseoverriding

Android @Override issues


I was using Java 1.7 for my Libgdx application, however i found i was getting a lot of "@Override" errors. So after searchin around online, i found out i should run with Java 1.6 compatibility to prevent this error. After going to window->preferences->java->compiler and changing the compatibility to 1.6, i find that i'm still receiving the @Override errors (The method ... must override a superclass method).

Any idea why this would still be happening? Do i really need to specify "@Override" for a function to override and carry out as scheduled by the Interface/Masterclass??

Here's the code if that helps:

package cowdawg.libgdx.namespace;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.khronos.opengles.GL10;

import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.files.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.graphics.GL11;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.g3d.loaders.obj.ObjLoader;

public class LifeCycle implements ApplicationListener {

    String head;
    Mesh model;
    private PerspectiveCamera camera;

    @Override
    public void create() {
        //super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        InputStream stream = null;
        try 
        {
            stream = Gdx.files.internal("Head/Head.obj").read();
            model = ObjLoader.loadObj(stream,true);
            stream.close();
        } 
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
        Gdx.gl10.glTranslatef(0.0f, 0.0f, -3.0f);

        //Mesh m;
        //InputStream in = Gdx.files.internal("data/cube.obj").read();
        //m = ObjLoader.loadObj(in);
        //m.render(GL10.GL_TRIANGLES);
    }

    @Override
    public void dispose(){
    }

    @Override
    public void pause(){
    }

    protected int lastTouchX;
    protected int lastTouchY;
    protected float rotateZ = 0.01f;
    protected float increment = 0.01f;

    @Override
    public void render()
    {
        Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        camera.update();
        camera.apply(Gdx.gl10);
        Gdx.gl10.glTranslatef(0.0f, 0.0f, -3.0f);
        Gdx.gl10.glRotatef(rotateZ, rotateZ, 5.0f, rotateZ);
        model.render(GL10.GL_TRIANGLES);

        if (Gdx.input.justTouched())
        {
        }
        else if (Gdx.input.isTouched())
        {
        }
        rotateZ += increment;
        System.out.println(""+rotateZ);
    }

    @Override
    public void resize()
    {

    }

    @Override
    public void resume()
    {

    }

    @Override
    public void resize(int arg0, int arg1) {
        // TODO Auto-generated method stub

    }
}

Solution

  • @Override annotation is just a safety mechanism. It is just a hint for the compiler the method is intended to override a parent method. If the method is not an override of a parent method compiler error is triggered.

    Using it is optional, but could be useful for detecting method name/parameter typos.