0

I have a problem with my game in Java, It runs perfectly fine on windows computers but really laggy on mac (I've tested it on a few, all decent specs).

After looking in the console I get a nullPointerException error! I never noticed it before as it doesn't effect game play! I don't think this is the cause to it slowing down on macs but I'm not too sure.

So I guess I have two problems..

public void keyPressed(KeyEvent key) {
    gsm.keyPressed(key.getKeyCode()); (line 120)
}

Here is what the console spat out:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at KezPro.GamePanel.keyPressed(GamePanel.java:120)
at java.awt.Component.processKeyEvent(Component.java:6372)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2809)
at java.awt.Component.processEvent(Component.java:6191)
at java.awt.Container.processEvent(Container.java:2084)
at java.awt.Component.dispatchEventImpl(Component.java:4776)
at java.awt.Container.dispatchEventImpl(Container.java:2142)
at java.awt.Component.dispatchEvent(Component.java:4604)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1856)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:722)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1000)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:865)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:686)
at java.awt.Component.dispatchEventImpl(Component.java:4648)
at java.awt.Container.dispatchEventImpl(Container.java:2142)
at java.awt.Window.dispatchEventImpl(Window.java:2492)
at java.awt.Component.dispatchEvent(Component.java:4604)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
user2245512
  • 107
  • 1
  • 2
  • 5
  • 4
    Well, I'm guessing that either gsm is null or key is null – MadProgrammer Jul 21 '15 at 21:35
  • It appears that your problems and the NPE are occurring intermittently or only occurring on one platform and not another. If so, it suggests that you may have a threading issue, that you might be making Swing calls off of the Swing event thread. But having said this, it's difficult to tell given the limited information that you've posted. Consider improving your question for us. – Hovercraft Full Of Eels Jul 21 '15 at 21:36

0 Answers0