File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Incompatible types error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Incompatible types error" Watch "Incompatible types error" New topic

Incompatible types error

Joniela Geldenhuys

Joined: Aug 24, 2011
Posts: 10
Helo I've been struggling for hours now!! I'm doing a java course and I must code an interactive balancing calculator! my textbook does not explain the work very nice so now I'm stuck!!!
This is what I coded but when I compile they give me 4 errors saying incompatible types! I don't know what I'm doing and I feel so stupid!! Please help!!

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Which book are you using, and how old is it?
Why are you using Readers, rather than a Scanner? A Scanner will give the input directly converted to the Java™ type required. Rather than your reading the line as a String and trying to assign that to the openingBalance amount, which is a double, so the compiler cannot achieve that (hence your error message), you can get the input converted directly without having to mess about with parseXXX method. So you can get the input in the correct type for money, which is not float nor double, but BigDecimalAnd there is a serious error in that code. So as not to let people think you are getting that code without any effort, I shall "forget" to correct that error (which appears twice). And I have respelt some of your variable names.
I agree. Here's the link:
subject: Incompatible types error
It's not a secret anymore!