float to int error, certainly something dumb...
in
Programming Questions
•
1 year ago
Hi all,
I've a sketch that throw me a "cannot convert float to int" exception, but it seems illogic to me.
Here is the code :
Every commented line does not throw any exception and work as excpected (thats why it seems illogic to me)
If I delete all the loop folks and keep only the 6th, 7th and 8th lines, all works fine even if they are somewhat similar
Processing seems to see x, y and z as integer when I am in the for statement, even if they are declared as float.
does anyone have an idea ?
thanks
Ge
ps : sorry for my bad english :)
I've a sketch that throw me a "cannot convert float to int" exception, but it seems illogic to me.
Here is the code :
- class Points {
- float x, y, z;
- char axis;
- public Points(String[] pieces) {
- // x = float(pieces[1].substring(1));
- // y = float(pieces[2].substring(1));
- // z = float(pieces[3].substring(1));
- for (int x=1;x<=pieces.length-1;x++) {
- axis = pieces[x].charAt(0);
- switch(axis) {
- case 'X' : x = float(pieces[x].substring(1)); break;
- case 'Y' : y = float(pieces[x].substring(1)); break;
- case 'Z' : z = float(pieces[x].substring(1)); break;
- // case 'X' : println("X ---> " + pieces[x].substring(1)); break;
- // case 'Y' : println("Y ---> " + pieces[x].substring(1)); break;
- // case 'Z' : println("Z ---> " + pieces[x].substring(1)); break;
- default: break;
- }
- }
- }
- }
Every commented line does not throw any exception and work as excpected (thats why it seems illogic to me)
If I delete all the loop folks and keep only the 6th, 7th and 8th lines, all works fine even if they are somewhat similar
Processing seems to see x, y and z as integer when I am in the for statement, even if they are declared as float.
does anyone have an idea ?
thanks
Ge
ps : sorry for my bad english :)
1