This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!