Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encountering problems in displaying the amount in label

 
thopex Arcilla
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im having problems with these code.



String str="";
Double amount = Double.parseDouble(str);

//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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Randall Twede
Ranch Hand
Posts: 4467
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you will need to post a little more code than that
 
thopex Arcilla
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


there is no output on the label.
 
Paul Clapham
Sheriff
Posts: 21314
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
thopex Arcilla
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will provide screenshots and post my codes to be more specific.

Thanks for all the response.

I want to be more proficient in java language just like you guys.


 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don’t post screenshots if possible Use copy-and-paste.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic