I'm developing a java program and my problem is that I want to write a general method for calling a specific method on a few classes, and the class is not known.
for example in normal use i write this piece of code for RootLayoutController class and it works:
RootLayoutController controller = loader.getController();
controller.setMainApp(this)
but the problem is that i have to write a lot of methods to call them! so i created PageController interface ( with setMainApp() inside ) and implemented it in RootLayoutController and other classes ; then changed the method to this:
Object controller = loader.getController();
((PageController) controller).setMainApp(this);
but it throws classcastexception and I don't know much about interface so I can't debug it! thanks so much
PageControllerinterface?loader.getController()is not returning aPageController. But you haven't told us what it does return, so I can't say any more than that.