Javafx 8 Java方法在自动分配ID时跳过两个数字。

Javafx 8 Java方法在自动分配ID时跳过两个数字。,javafx-8,Javafx 8,下面是我的add-product方法,每次添加时跳过两个数字 自动在保存新产品时分配新ID。我改变了这个 方法多次无效。任何建议都会大有帮助 @FXML private void goSaveNewProduct(ActionEvent event) { Products newProduct = new Products(); Boolean save = false; Double newProductCost = Double.parseDouble(priceTe

下面是我的add-product方法,每次添加时跳过两个数字 自动在保存新产品时分配新ID。我改变了这个 方法多次无效。任何建议都会大有帮助

@FXML
private void goSaveNewProduct(ActionEvent event) {
    Products newProduct = new Products();
    Boolean save = false;
    Double newProductCost = Double.parseDouble(priceTextField.getText());
    Double newTotal = product.getPartsTotal();

if (isAddProductValid()){
   newProduct.setProductName(productNameTextField.getText());            
   newProduct.setProductInStock(Integer.parseInt(invTextField.getText()));         
   newProduct.setProductPrice(Double.parseDouble(priceTextField.getText()));            
   newProduct.setProductMaximum(Integer.parseInt(maxTextField.getText()));            
   newProduct.setProductMinimum(Integer.parseInt(minTextField.getText()));
   newProduct.setAssociatedParts(associatedPartsTable.getItems());
    }    
    if (Objects.equals(newTotal, newProductCost)) {
        save = true;
        mainApp.getProductsData().add(newProduct);
        addProductsStage.close();  
    }
    else {                  
        // Warn user product price is not correct.
        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.initOwner(mainApp.getPrimaryStage());
        alert.setTitle("Product Price Warning");
        alert.setHeaderText("Please Correct Product Price!");
        alert.setContentText("Product price must equal the cost of parts!");
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == ButtonType.OK){
        // ... user chose OK
        save = false;
         } else {
        // ... user chose CANCEL or closed the dialog
        }
    }    
}
这是我的方法,可以得到零件的总数:

// returns the total of all parts price.
public Double getPartsTotal() {
    double result = 0.0;
    if(associatedParts != null) {
    for(int i = 0 ; i < associatedParts.size(); i++) {
    result += associatedParts.get(i).getPartPrice();
    }
    }
    return result;
}
//返回所有零件价格的总和。
公共双getPartsTotal(){
双结果=0.0;
if(关联部件!=null){
对于(int i=0;i
向我们展示您实际使用的
产品
构造函数。解决问题。我无意中在addproducts文件中有两个产品构造函数。哈哈,骗我。对不起,我第一次发错了。这就是我应该派去的那个建筑工人。公共产品(String productName、Integer productInStock、Double productPrice、ObservableList associatedParts)。
// returns the total of all parts price.
public Double getPartsTotal() {
    double result = 0.0;
    if(associatedParts != null) {
    for(int i = 0 ; i < associatedParts.size(); i++) {
    result += associatedParts.get(i).getPartPrice();
    }
    }
    return result;
}