I’m new to JFX, so this question probably has an obvious answer.
When I started my game I was following a tutorial. The source is at https://github.com/AlmasB/FXTutorials/tree/master/src/com/almasb/asteroids.
The developer who wrote it had different objects within the game represented by private static classes declared in the main Java file, each of which extended a single broad “Game Object” class written in another file. When I needed a new method or member variable I added it to this Game Object class to avoid cluttering the inline class declarations in the main file. Eventually I decided that that didn’t make sense and it shouldn’t be the case that every single game object has various data and methods it will never use. So I started splitting these private classes out into their own files and giving each only what it needed.
As a result, in many of my function calls to various objects, I can’t access those methods. This wasn’t a problem when these classes were private static classes of the Application.
For example:
Text currentHealth = new Text(0, 20,"Health: " + player.getHealth());
dataPane.getChildren().set(0, currentHealth);
In this case the IDE lets me attempt to run the program, but when it launches there’s a null pointer exception at that first line.
I tried something like:
actionPane.getChildren().get(0).somePlayerClassMethod();
It also doesn’t work. Though index 0 of that list definitely is the player object, I can’t access any methods related to the Player or Game Object classes (player is both).
I’m just not clear on why moving these classes into their own files made it difficult to access their instantiations’ methods. Each of them is a child of a Pane, which may or may not be relevant.
Again, the only thing that seems to have changed is that these classes are no longer private static classes within the Application class. Any ideas?
Edit: fixed typos.