wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes compilation errors: possible loss of precision, incompatible types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation errors: possible loss of precision, incompatible types" Watch "compilation errors: possible loss of precision, incompatible types" New topic
Author

compilation errors: possible loss of precision, incompatible types

Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
I am running into this error:





^
BenHultinProg2.java:46: incompatible types
found : java.lang.String
required: double
double totalPPoints = hw1.getPPoints() + hw2.getPPoints() + hw3.
getPPoints() + hw4.getPPoints();

^
BenHultinProg2.java:53: possible loss of precision
found : double
required: int
switch (lGrade) {
^




I am stumped about both of these errors, I have no idea how Strings got involved in the code and I have removed all traces of ints as well for the second error, yet it still persists.

here is my driver class:




my driven class is:



I appreciate any suggestions you have:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Those are not your real compiler errors; I don't get the first one about String and double when I try your code.

As for the second one, switch statements can only accept int and smaller (byte, short and char). long, float and double are not allowed. Also, you entire switch structure is illegal. Switch statements only work on exact values. For example:
You'll need to switch to an if-statement:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
Thanks a lot for the pointer, I will be sure to remember that detail. after making a a couple adjustments I was able to get rid of the errors above. Thanks again for the help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: compilation errors: possible loss of precision, incompatible types