2017-04-10 20 views
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); 

回答

0

我通過移除類廣播公司,這是完全沒有必要的解決了這個。現在該方法調用按預期工作!

@FXML 
public void initialize() { 
    bQuit.setOnAction(event -> Platform.exit()); 
    bConnect.setOnAction(d -> serverConnection()); 
    aliasField.setOnAction(a -> { 

     alias = aliasField.getText(); 

     Input.setOnAction(b -> { 
      userAnswer = Input.getText(); 
     }); 
    }); 
    aliasField.setPromptText("Alias"); 
    Input.setPromptText("And your answer is:"); 
} 

public void main(String[] args) { 
} 

public void serverConnection() { 
    try { 
     ServerSocket quizSocket = new ServerSocket(serverPort); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    ExecutorService executor = Executors.newFixedThreadPool(10000); 

    Task<Void> connection = new Task<Void>() { 
相關問題