我有这个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; }
答案 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()方法。