Skip to main content

Using Interfaces and their methods

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
SuperJava2000
Offline
Joined: 2014-07-26

I'm working on a Libgdx Project but I have a basic java question. I still don't fully grasp how interfaces are used. You see I'm trying to access the method from the interface in my code here. Its overriden in another class that is in a seperate project from the other two. The core project cannot read from the android project which contains "MainActivity" which is why I must do it this way. Currently the call to the method from the Game_Screen class returns a null pointer. How can I properly call this method? Thanks in advance.

public interface Controller {

public void show ();
}

public class MainActivity extends AndroidApplication implements AdController {

@Override
public void show() {

System.out.println("L");
}
}

public class Game_Screen implements Screen {

private Controller controller;

public Game_Screen(Controller controller) {

this.controller = controller;
adController.show();
}
}