Re: troubles with CardLayout
Where does the NullPointerException occur?
In general I would want a Game class quite separate from the gui panels. Moving a character would involve an instance of this class being made aware of players new position. The various card panels would hold a reference to the Game instance (so the player could be shown at the right place)
With this separation of game (aka "model") and the panels (aka "views") the logic of up key at the top would be simplified: tell the game the player has moved, switch to the new panel withtn the layout. The point isthe panels wouldn't keep or have to update information about the player position - the game would do that and the panels (eg when they painted themselves) would ask the game.
Re: troubles with CardLayout
Whenever you ask a question about NPE's, you will want to show which line throw the exception.
Re: troubles with CardLayout
ahh my bad its here
Code:
if(keyStroke.getKeyCode() == 38 && gameArea.getUserLocation().getRow() == 0)
when I try and move the character in the new JPanel it tries to grab the userLocation from gameArea (the old JPanel) but it has already set to null.
In response to pbrockway2: i should elaborate the JPanels that contain the games area are from a class called Grid which extends JPanel. Grid contains all the information you described i.e. the players position and such.