So this has been really bothering me: I am getting a number format exception somewhere in the following code (this is on a button btw, am doing a GUI for school):
String provider = clientInfo.getMediAidProvider();
String line = "";
int totalCost = treatmentInfo.getTotalCost();
System.out.println("P" + totalCost);
double percentPayout = 0.0;
double totalPayed = 0.0;
double toBePayed = 0.0;
int max = 0;
int min = 0;
try {
Scanner sc = new Scanner(new File(provider + "Momentum Algorithm.txt"));
while (sc.hasNextLine()) {
line = sc.nextLine();
if (line.contains("*")) {
String pPayout = line.substring(line.indexOf("=") + 1, line.indexOf("%"));
percentPayout = Integer.parseInt(pPayout);
totalPayed = totalCost * (percentPayout / 100);
toBePayed = totalCost - totalPayed;
System.out.println("D" + percentPayout);
System.out.println("E" + totalPayed);
System.out.println("?" + toBePayed);
} else {
max = Integer.parseInt(line.substring(line.indexOf("~") + 2, line.indexOf("=") - 1));
min = Integer.parseInt(line.substring(0, line.indexOf("~") - 1));
System.out.println("{" + min);
System.out.println("/" + max);
if (totalCost >= min && totalCost <= max) {
String pPayout = line.substring(line.indexOf("=") + 1, line.indexOf("%"));
percentPayout = Integer.parseInt(pPayout);
totalPayed = totalCost * (percentPayout / 100);
toBePayed = totalCost - totalPayed;
System.out.println("+" + percentPayout);
System.out.println("0" + totalPayed);
System.out.println("*" + toBePayed);
break;
}
}
}
} catch (FileNotFoundException | NumberFormatException e) {
System.out.println(e);
}
tblInvoice.setValueAt("R" + totalCost, 0, 0);
tblInvoice.setValueAt(percentPayout + "%", 0, 1);
tblInvoice.setValueAt("R" + totalPayed, 0, 2);
tblInvoice.setValueAt("R" + toBePayed, 0, 3);
Essentially I am bringing in objects, converting to strings and then to integers or doubles, or just going straight from objects to ints. Here is the error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException:
Cannot format given Object as a Number
at java.text.DecimalFormat.format(DecimalFormat.java:507)
at java.text.Format.format(Format.java:157)
at javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer.configureValue(SynthTableUI.java:802)
at javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer.getTableCellRendererComponent(SynthTableUI.java:789)
at javax.swing.JTable.prepareRenderer(JTable.java:5723)
Plus many more locations, but none of them actually link to my GUI Class or any other custom created class. So here is the problem: it gives me the exact problem, NumberFormatException, but nowhere does it tell me WHERE the error is. I have tried using System.out.println to trace through the code and it all seems to be running fine. I have no idea WHAT object is being passed to the Integer.parseInt method that it won't accept or where it is passing the object. Any help will be much appreciated!