I use for determine the space between the first two fingers Android SDK 23 marshmallow
private float spacing(WrapMotionEvent event) {
// ...
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return (Float)Math.sqrt (x * x + y * y);
}
warning message
Error:(415, 32) error: incompatible types: double cannot be converted to Float
Math.sqrt
returns a double
, even if the input is float
.
You can't convert double
to Float
(the wrapper type) other than explicitly going via float
(the primitive type)... but that's okay, because you don't actually want Float
. The return type of your method is float
, so just cast to that instead:
return (float) Math.sqrt(x * x + y * y);
If the return type of your method had been Float
, you could still use the same line of code, and let the compiler add auto-boxing from float
to Float
.
See more on this question at Stackoverflow