This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Calculator that accepts floating point values  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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: 3353
33
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!