-8

I am trying to set up a Server for a Worms-like game made in Java (to allow Multiplayer and in-game chat) but I have this specific problem.

I have tried changing the import, but it didn't resolve the issue.

Screenshot here : https://i.stack.imgur.com/cAlQK.png

package Server;

import java.io.PrintWriter;

import java.net.ServerSocket;

import java.util.HashSet;

import java.util.logging.Handler;

public class Server {
    private static final int PORT = 9001;

    private static HashSet<String> names = new HashSet<String>();
    private static HashSet<PrintWriter> writers =
            new HashSet<PrintWriter>();

    public static void main(String[] args) throws Exception {
        System.out.println("The chat server is running.");
        try(ServerSocket listener = new ServerSocket(PORT)) {
            while (true) {
                new Thread(new Handler(listener.accept())).start();
            }
        }
    }
}
Dennis Meng
  • 5,109
  • 14
  • 33
  • 36
Yaaya26
  • 1
  • 1
  • 3

1 Answers1

1

As the error says, an abstract class cannot be instantiated, i.e., we cannot precede it with the word new, unless you also add the class body and implement any abstract methods. Alternately, you can create a class that extends Handler, and again make sure to add all of the abstract methods.

new Handler() {

    @Override
    public void close() throws SecurityException {
        // TODO Auto-generated method stub

    }

    @Override
    public void flush() {
        // TODO Auto-generated method stub

    }

    @Override
    public void publish(LogRecord arg0) {
        // TODO Auto-generated method stub

    }

};
user184994
  • 17,791
  • 1
  • 46
  • 52