Class is not Abstract and does not Override error in Java

Phil picture Phil · May 15, 2013 · Viewed 71.3k times · Source

I am getting a compile time error with Java:

MyClass is not abstract and does not override abstract method
onClassicControllerRemovedEvent(
wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent)
in wiiusejevents.utils.WiimoteListener)

Here is the class:

import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;


public class MyClass implements WiimoteListener{

    public void onButtonsEvent(WiimoteButtonsEvent arg0) {
        System.out.println(arg0);
        if (arg0.isButtonAPressed()){
            WiiUseApiManager.shutdown();
        }
    }

    public void onIrEvent(IREvent arg0) {
        System.out.println(arg0);
    }

    public void onMotionSensingEvent(MotionSensingEvent arg0) {
        System.out.println(arg0);
    }

    public void onExpansionEvent(ExpansionEvent arg0) {
        System.out.println(arg0);
    }

    public void onStatusEvent(StatusEvent arg0) {
        System.out.println(arg0);
    }

    public void onDisconnectionEvent(DisconnectionEvent arg0) {
        System.out.println(arg0);
    }

    public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
        System.out.println(arg0);
    }

    public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
        System.out.println(arg0);
    }

    public static void main(String[] args) {
        Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
        Wiimote wiimote = wiimotes[0];
        wiimote.activateIRTRacking();
        wiimote.activateMotionSensing();
        wiimote.addWiiMoteEventListeners(new MyClass());
    }
}

Can I get a better explanation of what this error means?

Answer

zw324 picture zw324 · May 15, 2013

Your class implements an interface WiimoteListener, which has a method onClassicControllerRemovedEvent. However, the methods in interfaces are abstract, which means they are essentially just contracts with no implementations. You need to do one of the things here:

  1. Implement this method and all the other methods that this interface declares, which make your class concrete, or
  2. Declare your class abstract, so it cannot be used to instantiate instances, only used as a superclass.