NullPointerException in IDE at unAppStateAction.java:208

During the past couple days I’ve begin getting null pointer exceptions when I right-click on certain class names in the source-code editor. It seems to be easily reproducible in my Windows 7 environment. Here is the most recent stack trace:

Checking page id 1,386,958,573 vs stored id 1,386,958,573
java.lang.NullPointerException
at com.jme3.gde.core.appstates.RunAppStateAction$2.run(RunAppStateAction.java:208)
at com.jme3.gde.core.appstates.RunAppStateAction$2.run(RunAppStateAction.java:191)
at org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:488)
at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:584)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:155)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:139)
at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:201)
at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:198)
at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:176)
at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:360)
at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:74)
at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:198)
at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:106)
at org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:438)
at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:409)
at com.jme3.gde.core.appstates.RunAppStateAction.checkData(RunAppStateAction.java:225)
at com.jme3.gde.core.appstates.RunAppStateAction.createContextAwareInstance(RunAppStateAction.java:95)
at org.netbeans.modules.editor.NbEditorKit.translateContextLookupAction(NbEditorKit.java:344)
at org.netbeans.modules.editor.NbEditorKit.access$200(NbEditorKit.java:133)
at org.netbeans.modules.editor.NbEditorKit$NbBuildPopupMenuAction.addAction(NbEditorKit.java:455)
at org.netbeans.modules.editor.NbEditorKit$NbBuildPopupMenuAction.buildPopupMenu(NbEditorKit.java:434)
at org.netbeans.editor.ext.ExtKit$BuildPopupMenuAction.actionPerformed(ExtKit.java:281)
at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:339)
at org.netbeans.spi.editor.AbstractEditorAction.actionPerformed(AbstractEditorAction.java:444)
at org.netbeans.editor.EditorUI.showPopupMenu(EditorUI.java:1763)
at org.netbeans.editor.EditorUI$7.run(EditorUI.java:1696)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Is your class maybe missing a package name? Java classes should always be in a package.

This class being edited is in fact in an unnamed package. This may be poor style, but I believe it is legal Java per JLS 7.4.2.

@sgold said: This class being edited is in fact in an unnamed package. This may be poor style, but I believe it is legal Java per JLS 7.4.2.

“default” package has been frowned upon for a long time. It’s still valid in the spec but a bunch of more modern things just plain won’t accept it anymore.

It should be avoided.

Yeah, I could avoid that error in a future version (so thanks for mentioning) but as mentioned, its best to always use packages.

Thanks for the advice, @normen. In this instance, I was working on a project created by someone else.

By the way, the IDE is particularly unhelpful in this area. For instance, the “Rename…” and “Delete” options for the default package are grayed out. Apparently I need to delete the entire project and rework it outside the IDE.

If the IDE isn’t intended to support unnamed packages, perhaps it should put up an error (or at least a warning: “monkey brains ahead”) when the user tries to open a project containing such a package.

Just make an actual package and move your file there, the IDE will help you with refactoring it. Obviously you cannot rename the default package as it is the root, it is not a package.

The IDE does warn you about making new classes without a package, you probably ignored that warning. Anyway glad your issue is solved.

@sgold said: Thanks for the advice, @normen. In this instance, I was working on a project created by someone else.

By the way, the IDE is particularly unhelpful in this area. For instance, the “Rename…” and “Delete” options for the default package are grayed out. Apparently I need to delete the entire project and rework it outside the IDE.

If the IDE isn’t intended to support unnamed packages, perhaps it should put up an error (or at least a warning: “monkey brains ahead”) when the user tries to open a project containing such a package.

Can you move the class to a package?

@pspeed said: Can you move the class to a package?

Yes, that does the trick. The unnamed package disappears as soon as its last class is removed.

@sgold said: Yes, that does the trick. The unnamed package disappears as soon as its last class is removed.

Again, its not an unnamed package. Its just all classes that have no package.

@normen said: Just make an actual package and move your file there, the IDE will help you with refactoring it. Obviously you cannot rename the default package as it is the root, it is not a package.

The IDE does warn you about making new classes without a package, you probably ignored that warning. Anyway glad your issue is solved.

As I say, I was working on someone else’s code.

Unfortunately, I don’t recall precisely how I got into this situation. Perhaps I renamed a package to “” using Refactor … -> Rename

Anyway, now I know a few more things to do (and not do) if this situation arises again. Thanks for your help.