如何修复错误“TimeBackUp.java使用未经检查或不安全的操作”?

时间:2017-01-27 21:19:16

标签: java

我有以下名为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" 但是我在代码中没有看到问题中的答案所带来的问题。

有人知道如何修复此错误吗?

1 个答案:

答案 0 :(得分:2)

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

这意味着我没有写出正确的TreeItem<String>;,而是写了TreeItem;