• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calculator that accepts floating point values

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys. I'm currently learning to use Android Studios, and I'm quite stuck. The exercise I'm doing is to create a calculator, with the buttons +,-,/. I am done with the calculator, and I've gotten it to work, except for one instance.

Whenever I put in a floating number, even with only one decimal, the program crashes. I experienced this when trying to divide by zero as well, which I solved by surrounding the code with try and catch.

However, I am clueless to what I should to get decimals to work. I would very much appreciate if you could take a look at my code and help me with this issue. My program contains a main java class, and a main xml_class. I'll post them down below:

MainActivity.java:



activity_main.xml:

 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Whenever I put in a floating number, even with only one decimal, the program crashes.


Can you copy the section of the logcat where the error message is shown and paste it here?
It should show the source line number and the name of the method that was called.

Where is the parse method for floating numbers?  I only see the parseInt method which is for integers.
 
Alas, poor Yorick, he knew this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic