mardi 29 août 2017

Java Listener Error: Exception in thread "main" java.lang.Error: Unresolved compilation problems:

I saw a video tutorial where the code works. Its about to Programm a console. In The video this code works:

    package konsole;

    import java.util.Scanner;
    import console.Console;
    import konsole.commands.Echo;
    import console.ConsoleCommand;

public class Konsole {
public static final Console c = new Console();

public static void main(String[] args) {
    final Scanner s = new Scanner(System.in);
    c.registerCommand(new Echo());
    c.addListener(new ConsoleListener() {
        public void onCommand(ConsoleCommand cmd, String cmdname, String[] args) {
            Konsole.c.writeInfo("Command executed:" + cmdname);
        }
    });

    while(true) {
        System.out.print("consoleuser>");
        String in = s.nextLine();
        if(in.isEmpty() == false) {
            String[] scmd = in.split(" ");
            String cmdname = scmd[0];
            String[] cmdargs = new String[scmd.length - 1];
            for (int i = 1; i < scmd.length; i++) {
                cmdargs[i - 1] = scmd[i]; 
            }
            c.executeCommand(cmdname, cmdargs);
        } else {
            continue;
        }
    }
}

}

I get the Error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method addListener(ConsoleListener) in the type Console is not applicable for the arguments (new ConsoleListener(){})ConsoleListener cannot be resolved to a type

Aucun commentaire:

Enregistrer un commentaire