2013-08-22 59 views
0

我有午餐Java線程這個Java代碼:警告:[選中]選中轉換duaring編譯

public void start(Stage primaryStage) 
    { 
     // TODO when Java 8 is released use this to set default Skin 
     //setUserAgentStylesheet(STYLESHEET_CASPIAN); 

     final Task<ObservableList<String>> friendTask = new Task() 
     { 
      @Override 
      protected ObservableList<String> call() throws InterruptedException 
      { 
       ObservableList<String> foundFriends = 
         FXCollections.<String>observableArrayList(); 
       ObservableList<String> availableFriends = 
         FXCollections.observableArrayList("Network Module", "User Module", "User Interface", "User Controls"); 

       updateMessage("Loading Modules . . ."); 
       for (int i = 0; i < availableFriends.size(); i++) 
       { 
        Thread.sleep(250); 
        updateProgress(i + 1, availableFriends.size()); 
        String nextFriend = availableFriends.get(i); 
        foundFriends.add(nextFriend); 
        updateMessage("Loading Modules . . . Loading " + nextFriend); 
       } 

       updateMessage("All Modules are loaded."); 
       Thread.sleep(1500); 

       return foundFriends; 
      } 
     }; 

     showSplash(primaryStage, friendTask); 
     new Thread(friendTask).start(); 
     initMainStage(primaryStage); 
    } 

我可以編譯代碼,但我得到這樣的警告消息:

Compiling 26 source files to /home/rcbandit/Desktop/test/DX-57DC/build/classes 
/home/rcbandit/Desktop/test/DX-57DC/src/com/dx57dc/main/DX57DC.java:75: warning: [unchecked] unchecked conversion 
     final Task<ObservableList<String>> friendTask = new Task() 
    required: Task<ObservableList<String>> 
    found: <anonymous Task> 
/home/rcbandit/Desktop/test/DX-57DC/src/com/dx57dc/main/DX57DC.java:139: warning: [unchecked] unchecked call to addListener(ChangeListener<? super T>) as a member of the raw type ObservableValue 
     task.stateProperty().addListener(new ChangeListener<Worker.State>() 
    where T is a type-variable: 
    T extends Object declared in interface ObservableValue 
2 warnings 

你能告訴我如何解決這個問題?

PS這是在那裏我獲得第二次警告:

private void showSplash(final Stage mainStage, Task task) 
    { 

     final Stage splashStage = new Stage(); 
     progressText.textProperty().bind(task.messageProperty()); 
     loadProgress.progressProperty().bind(task.progressProperty()); 
     task.stateProperty().addListener(new ChangeListener<Worker.State>() 
     { 
      @Override 
      public void changed(ObservableValue<? extends Worker.State> observableValue, Worker.State oldState, Worker.State newState) 
      { 
       if (newState == Worker.State.SUCCEEDED) 
       { 
        loadProgress.progressProperty().unbind(); 
        loadProgress.setProgress(1); 
        //mainStage.setIconified(false); 
        splashStage.toFront(); 
        // Set splash screen fadeout effect 
        FadeTransition fadeSplash = new FadeTransition(Duration.seconds(0.4), splashLayout); 
        fadeSplash.setFromValue(1.0); 
        fadeSplash.setToValue(0.0); 
        fadeSplash.setOnFinished(new EventHandler<ActionEvent>() 
        { 
         @Override 
         public void handle(ActionEvent actionEvent) 
         { 
          splashStage.close(); 
          mainStage.show(); 
          mainStage.toFront(); 
         } 
        }); 
        fadeSplash.play(); 
       } // todo add code to gracefully handle other task states. 
      } 
     }); 
     Scene splashScene = new Scene(splashLayout); 
     splashStage.initStyle(StageStyle.UNDECORATED); 
     final Rectangle2D bounds = Screen.getPrimary().getBounds(); 
     splashStage.setScene(splashScene); 
     splashStage.setX(bounds.getMinX() + bounds.getWidth()/2 - SplashWidth/2); 
     splashStage.setY(bounds.getMinY() + bounds.getHeight()/2 - SplashHeight/2); 
     splashStage.show(); 

     //StartPanel.initStartPage(mainStage); 

    } 

的問題是在這條線:

task.stateProperty().addListener(new ChangeListener<Worker.State>() 

我收到此錯誤信息:

Compiling 1 source file to /home/rcbandit/Desktop/test/DX-57DC/build/classes 
/home/rcbandit/Desktop/test/DX-57DC/src/com/dx57dc/main/DX57DC.java:138: warning: [unchecked] unchecked call to addListener(ChangeListener<? super T>) as a member of the raw type ObservableValue 
     task.stateProperty().addListener(new ChangeListener<Worker.State>() 
    where T is a type-variable: 
    T extends Object declared in interface ObservableValue 
1 warning 
compile: 

回答

1

,如果你正在使用java7,請使用

Task<ObservableList<String>> friendTask = new Task<>() 

否則,你可以隨時使用

Task<ObservableList<String>> friendTask = new Task<ObservableList<String>>()