for (int i = 0; i < 18; i++) {
line = file.readLine();
String[] word = line.split(";");
appartment[i] = new Appartment();
appartment[i].floor= Integer.parseInt(word[0]);
appartment[i].name = word[1];
appartment[i].money= Double.parseDouble(word[2]);
appartment[i].owner= word[3];
}
Could someone tell my why this is not working? Im reading from a file. I am trying to convert money from string to double, but it says
possible loss of precision.
required: int
found: double
I need doubles so the owners account also can go negative.
– It seems that
appartmentis an Array of typeAppartment, where the Appartement’s object field namedmoneyis ininttype.– But you are assingnig it the value as
doubletype, so you will need an explicit cast from double to int,Eg:
appartment[i].money= (int) Double.parseDouble(word[2]);