wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Encountering problems in displaying the amount in label Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Encountering problems in displaying the amount in label" Watch "Encountering problems in displaying the amount in label" New topic
Author

Encountering problems in displaying the amount in label

thopex Arcilla
Greenhorn

Joined: Jan 03, 2012
Posts: 10
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

Joined: Apr 06, 2010
Posts: 4369
    
    8

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

Joined: Oct 21, 2000
Posts: 4340
    
    2

you will need to post a little more code than that


SCJP
Visit my download page
thopex Arcilla
Greenhorn

Joined: Jan 03, 2012
Posts: 10
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 03, 2012
Posts: 10
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

Joined: Oct 13, 2005
Posts: 38441
    
  23
Please don’t post screenshots if possible Use copy-and-paste.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Encountering problems in displaying the amount in label