0
我必須創建一個類的實例,不調用非靜態方法。當我這樣做:當涉及到類的實例時出現問題:'Broadcaster中的Broadcaster(套接字)不能應用於0`
@FXML
public void initialize() {
bConnect.setOnAction(d -> {
try {
new Broadcaster().serverConnection();
} catch (IOException e) {
e.printStackTrace();
}
});
我收到此警告:Broadcaster (Socket) in Broadcaster cannot be applied to 0
。 我不知道指什麼變量。我該如何解決這個問題?
這是有事情做與插座的轉播類的部分:
public class Client {
private String serverAddress = "localhost";
private final int serverPort = 9001;
@FXML
public void initialize() {
bQuit.setOnAction(event -> Platform.exit());
bConnect.setOnAction(d -> {
try {
new Broadcaster().serverConnection();
} catch (IOException e) {
e.printStackTrace();
}
});
class Broadcaster extends Thread {
Socket clientSocket;
private BufferedReader read;
private PrintStream write;
int counter = 0; //Countern finns för att testa funktionen.
String questions;
public Broadcaster(Socket clientSocket) throws IOException {
this.clientSocket = clientSocket;
}
public void serverConnection() {
ExecutorService executor = Executors.newFixedThreadPool(10000);
Task<Void> connection = new Task<Void>() {
@Override
public Void call() {
try {
clientSocket = new Socket(serverAddress, serverPort);