Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException I cannot resolve
    primarykey
    data
    text
    <p>This is the method called when the player has to be removed from the game. Both these methods are in different classes.</p> <p><strong>GameboardGUI class</strong></p> <pre><code> Vector&lt;Player&gt; players = new Vector&lt;Player&gt;(); public void removePlayerFromGame(Player playerToRemove) { //go through the playerToRemove's properties and reset all their variables for(int i = 0; i &lt; playerToRemove.getPropertiesOwned().size(); i++) { //code to reset the player's properties to an unowned/unmodified state } //same with transports for(int i = 0; i &lt; playerToRemove.getTransportsOwned().size(); i++) { //code to reset the player's transports to an unowned/unmodified state } //just updating the vector based on the playerToRemove's position if(players.get(0) == playerToRemove) { players.remove(playerToRemove); updatePlayerInformation(); } else { players.remove(playerToRemove); updatePlayerVector(players); updatePlayerInformation(); } } </code></pre> <p>This is how the method is called: If the current player (fromMe) lands on a property and cant afford to pay the rent (i.e. their balance reaches 0 as a result of <code>takefrombalance(1200);</code>, currently hardcoded to 1200 to make testing easier) they are removed in the if statement <code>if(fromMe.isBankrupt())</code></p> <p><strong>Property Class</strong></p> <pre><code>GameboardGUI gui = new GameboardGUI(); public void payRent(Player fromMe, Player toYou, int rent) { //remove rent from the current player fromMe.takeFromBalance(1200); //add it to the owner toYou.addToBalance(rent); GameboardGUI.addGameFeedMessage(fromMe.getName() + " has paid " + rent + " in rent to " + toYou.getName()); GameboardGUI.addGameFeedMessage(toYou.getName() + "'s balance is now " + toYou.getBalance()); if(fromMe.isBankrupt()) { //THIS IS THE CALL THAT THROWS THE NullPointerException gui.removePlayerFromGame(fromMe); } else { GameboardGUI.addGameFeedMessage(fromMe.getName() + "'s balance is now " + fromMe.getBalance()); } } </code></pre> <p>Here is the stack trace when the line is reached:</p> <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at PropertyTile.payRent(PropertyTile.java:254) at PropertyTile.landedOnProperty(PropertyTile.java:239) at GameboardGUI.playerHasLanded(GameboardGUI.java:1905) at Player.setPosition(Player.java:82) at Player.movePlayer(Player.java:101) at GameboardGUI$11.actionPerformed(GameboardGUI.java:1536) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload