我有一个名为TimeBackUp.java的以下Java类,它是javafx应用程序的起点:

 import javafx.application.Application;
 import static javafx.application.Application.launch;
 import javafx.geometry.Insets;
 import javafx.geometry.Pos;
 import javafx.scene.Scene;
 import javafx.scene.control.*;
 import javafx.scene.layout.*;
 import javafx.scene.media.AudioClip;
 import javafx.stage.Stage;

 public class TimeBackUp extends Application {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Time Backup");

    Button button = new Button("Button");
    VBox vertLayout = new VBox(10);
    HBox horLayout1 = new HBox(20);
    MenuBar mb = new MenuBar();
    vertLayout.getChildren().add(mb);
    final Menu backupMenu = new Menu("Backups");
    final MenuItem backupNow = new MenuItem("Backup Now");
    final MenuItem backupSett = new MenuItem("Schedule Backups");
    backupMenu.getItems().add(backupNow);
    backupMenu.getItems().add(backupSett);
    backupNow.setOnAction(actionEvent -> {

    });
    mb.getMenus().add(backupMenu);
    mb.getMenus().add(backupMenu);
    horLayout1.setPadding(new Insets(25.0));
    ComboBox<String> DateCb = new ComboBox<>();
    DateCb.setMinWidth(100);
    DateCb.getItems().add("Date 1");
    vertLayout.getChildren().add(horLayout1);
    Label lbl = new Label("Select A Backup to View the Files:");
    lbl.setPadding(new Insets(5, 0, 0, 0));
    horLayout1.getChildren().add(lbl);
    horLayout1.getChildren().add(DateCb);
    TreeItem root = new TreeItem("Sample Backup");
    TreeView<String> tree = new TreeView<>(root);

    for (int i = 0; i <1000;i++){
        TreeItemPath tip = new TreeItemPath(new PathNode(false,"file" + i,"num" +i ));
        root.getChildren().add(tip);
    }
    vertLayout.getChildren().add(tree);

    DateCb.setOnAction(actionEvent -> {
        System.out.println(DateCb.getValue());
    });

    Scene scene = new Scene(vertLayout, 700, 500);
    primaryStage.setScene(scene);
    primaryStage.show();
}


每当我构建项目时,都会出现以下错误Note: /Users/yaakov/NetBeansProjects/TimeBackUp/src/timebackup/TimeBackUp.java uses unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details.

我在这里查看了问题和答案"uses unchecked or unsafe operations"
但是我在代码中的任何地方都看不到该问题的答案引起的问题。

有人知道如何解决此错误吗?

最佳答案

我解决了它,问题是我声明了一个没有通用类型的TreeItem。

意思是我没有写正确的TreeItem<String>;而是写了简单的TreeItem;

10-04 22:00