Я не могу заставить это работать. Я написал заметки, которые, надеюсь, объяснят, что я пытаюсь сделать. Консоль выдает ошибку на линии totalCost = totalCost.add(new BigDecimal(result));
Добавление BigDecimal в BigDecimal в Java
private void btn_motherboardActionPerformed(java.awt.event.ActionEvent evt) {
String cost = cb_motherboard.getSelectedItem().toString();
//gets item from combobox. Makes a string
Components.addElement(cost);// adds string to model
lb_computer_components.setModel(Components);//sets model to jlist
String result = cost.substring(cost.lastIndexOf('£') + 1);
//creates a substring containing information after £ (for example 45.99)
totalCost = totalCost.add(new BigDecimal(result));
//totalcost is a public bigdecimal, i want to add 45.99 to it in this example
String BD = totalCost.toString();
//change the new totalcost to a string
String stringTotal = n.format(BD);
//format that string to a currency
txt_total_computer.setText(stringTotal);
//output that string to a textfield
}
Вы пытались использовать отпечатки, чтобы увидеть значения переменных, чтобы увидеть, где он не работает? – user2097804
Какая ошибка? – Radiodef
Извините, он начинается как этот Исключение в потоке «AWT-EventQueue-0» java.lang.NullPointerException \t at computer.INterface.btn_motherboardActionPerformed (INterface.java:2324) – user3320339