• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Encountering problems in displaying the amount in label

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 27214
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Marshal
Posts: 75716
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don’t post screenshots if possible Use copy-and-paste.
 
What are you doing in my house? Get 'em tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic