I am following an online tutorial for a live wallpaper. During this I have encountered a problem which I find peculiar. The problem is that the constructor MyPoint in the code below says that it is getting String, int, int and that it needs String, float, float. However, the x and y in this constructor reference to the local floats x and y. I checked by selecting x or y in the constructor, and the local floats x or y would light up, so it should be getting floats as input. So why does it give this error?
@Override
public void onTouchEvent(MotionEvent event) {
if (touchEnabled) {
float x = event.getX();
float y = event.getY();
SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if (canvas != null) {
canvas.drawColor(Color.BLACK);
circles.clear();
circles.add(new MyPoint(String.valueOf(circles.size() + 1), x, y));
drawCircles(canvas, circles);
}
} finally {
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
super.onTouchEvent(event);
}
}
EDIT:
The exact error is: “The constructor MyPoint(String, float, float) is undefined”
With quick fix option: “Change constructor MyPoint(String, int, int) to MyPoint(String, float, float)”
A constructor does not request anything. It requires values of whatever type you have defined in the constructor signature. If you do not supply values of the correct type, then the compiler cannot compile your code since you have told it to instantiate an instance of MyPoint via it’s constructor receiving String, float, float which does not exist.
So the error is, as a minimum, in your “MyPoint” class. You might also have an error in the code you’ve shown if indeed the MyPoint constructor requires ints. However, looking at your code, it seems that float is more likely.
The error, and it’s solution, are straightforward.
In MyPoint, you have
You should also have
I am assuming that you want both. If you have no need for a constructor receiving x and y as ints, then simply change it.