I'm trying to create a class that inherits Canvas class of Android. My reason is adding more robust and useful methods to that class for my game framework. When I tried to cast my AdvancedCanvas object to Canvas in onDraw()
method. I do the drawing part in draw()
method which takes an advancedcanvas object as a parameter. It causes an exception;
java.lang.ClassCastException: android.view.Surface$CompatibleCanvas cannot be cast to com.example.x.AdvancedCanvas
Here is my code block below
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
AdvancedCanvas advancedcanvas = (AdvancedCanvas) canvas;
draw(advancedcanvas);
}
My real question is, is there any way to achieve that goal in the first place? Or any alternative ideas would be welcome. Thanks in advance.