我收到以下错误
无法访问类型的封闭实例
当我尝试添加此行时:
Receiver.this.getMyField()
尝试从另一个名为receiver
的类中获取值。
private void initSenderAndReceiver(final Socket clientSocket) {
Receiver receiver = new Receiver(clientSocket, chatView);
final Sender sender = new Sender(clientSocket, chatView);
sendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sender.sendMessage(chatBox.getText());
//sender.sendMessage(Receiver.this.Clientcoordinate1,Receiver.this.Clientcoordinate2);
//sender.sendMessage();
Receiver.this.getMyField();
chatBox.setText(""); //Clear the chat box
}
});
Thread receiverThread = new Thread(receiver);
receiverThread.run();
}
答案 0 :(得分:1)
尝试使用receiver.getMyField();
将final
声明为sender
对象。