Encountering problems in displaying the amount in label

//im having errors when i press the balance inquiry button. I cant display the balance on my savings class.
label.setText("Balance: "+savings.getBalance());

Can someone help me on this matter or suggest what is the best thing to do to avoid errors on my code? im using java netbeans 7.0 software

thanks.

Matthew Brown

Bartender

Posts: 4568

9

posted 4 years ago

Well, if that's exactly the code, then Double.parseDouble(str) is going to be a problem because str is an empty string, and so can't be converted to a double.

If that isn't exactly the code, what exactly is the problem? Are you getting an error message, it is doing nothing, or is it displaying the wrong value? There are lots of things that could possibly be going wrong, and you haven't given us enough information to guess.

Matthew Brown wrote:Well, if that's exactly the code, then Double.parseDouble(str) is going to be a problem because str is an empty string, and so can't be converted to a double.

If that isn't exactly the code, what exactly is the problem? Are you getting an error message, it is doing nothing, or is it displaying the wrong value? There are lots of things that could possibly be going wrong, and you haven't given us enough information to guess.

Then clearly you can't be calling that label.setText() method, because if you did then there would be something in the label. But you've already been told that Double.parseDouble(str) is going to throw an exception, which would certainly cause the code after that line to not be executed.