基本Java:错误:预期的类,接口或枚举

时间:2015-11-03 11:01:42

标签: java

我有这个Java程序导致these errors被抛出。

以下是源代码:

public class RcvThread2 implements Runnable {
private static final int sizeBuf = 50;
private Socket clientSocket;
private Logger logger;
private SocketAddress clientAddress; }

public RcvThread2(Socket clntSocket, SocketAddress clientAddress, Logger logger) {
this.clientSocket = clntSocket;
this.logger = logger;
this.clientAddress = clientAddress; }

2 个答案:

答案 0 :(得分:1)

在声明clientAddress后删除结束花括号。

否则你的构造函数声明不会编译。

在最后添加一个额外的结束花括号。

答案 1 :(得分:1)

进行以下更改

public class RcvThread2 implements Runnable {
    private static final int sizeBuf = 50;
    private Socket clientSocket;
    private Logger logger;
    private SocketAddress clientAddress;

    public RcvThread2(Socket clntSocket, SocketAddress clientAddress,
        Logger logger) {
        this.clientSocket = clntSocket;
        this.logger = logger;
        this.clientAddress = clientAddress;

    }

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

    }
}

问题在于}错误地放置了变量声明,因为类的主体在那里被关闭了。同时实现的Runnable接口和run方法没有被覆盖,所以我们也需要覆盖run()方法。