Skip to content
Advertisement

use getter to pass value failed in java

I am a beginner there are two classes that I want to use getter to pass the value of the field from another class. Therefore, I did something like this How do getters and setters work?

But it didn’t pass the value. I got IllegalArgumentException: bound must be greater than origin from the NimAIPlayer since its bound and origin can’t be the same value. What could be the reason?

Here is part of the NimAIPlayer class

JavaScript

And here is part of my NimGame class

JavaScript

Any help is highly appreciated.

Advertisement

Answer

Add a parameterized constructor in NimGame class

NimGame.java

JavaScript

NimAIPlayer.java

You can initialize NimGame object like this using parameterized constructor

JavaScript

Using NimGame nimGame = new NimGame() will initialize all fields with default values like null for object type and 0 for int type . This will result getting 0 for all interger fields when you print inside moveStone method .

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement