This site requires JavaScript, please enable it in your browser!
Greenfoot back
Upupzealot
Upupzealot wrote ...

2014/8/31

Enum and String exception when inspecting!

Upupzealot Upupzealot

2014/8/31

#
If an object has an enum varivable, when you try to "inspect" it, greenfoot got exception "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException". BTW, String in inspect was causing the same problem. I'm using Greenfoot 2.4(legacy) on windows 8.1, my jdk level is 1.8.0_20.
Upupzealot Upupzealot

2014/8/31

#
Just got Greenfoot 2.3 tested(on the same computer, same OS), it does not have this problem! It seems something is wrong with the new version.
davmac davmac

2014/9/1

#
I am not able to reproduce this. Could you provide the exact code that you have, and the complete stack trace please?
Upupzealot Upupzealot

2014/9/1

#
The problem should be the string problem, not the enum class. I tested in a new project to locate the problem. It has no executable code, just one line " String s = "asdsadsa"; " in a subclass of Actor, and when i try to inspect one of it's object, the exception still pops up, and Greenfoot 2.3 dont. the stack trace comes below: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at bluej.debugmgr.inspector.ObjectInspector.listElementSelected(ObjectInspector.java:413) at bluej.debugmgr.inspector.Inspector.valueChanged(Inspector.java:408) at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184) at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164) at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211) at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405) at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415) at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:459) at javax.swing.JTable.setRowSelectionInterval(JTable.java:2166) at bluej.debugmgr.inspector.Inspector.update(Inspector.java:325) at bluej.debugmgr.inspector.ObjectInspector.<init>(ObjectInspector.java:139) at greenfoot.gui.inspector.GreenfootObjectInspector.<init>(GreenfootObjectInspector.java:49) at greenfoot.gui.GreenfootInspectorManager.getInspectorInstance(GreenfootInspectorManager.java:78) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$2.actionPerformed(WorldHandlerDelegateIDE.java:199) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.AbstractButton.doClick(AbstractButton.java:376) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877) at java.awt.Component.processMouseEvent(Component.java:6525) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6290) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2739) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746) at java.awt.EventQueue.access$400(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:697) at java.awt.EventQueue$3.run(EventQueue.java:691) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:719) at java.awt.EventQueue$4.run(EventQueue.java:717) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:716) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
davmac davmac

2014/9/1

#
Ok, I've got it. The problem is caused by having any package-private (i.e. not 'public', not 'private') instance variable of reference type (not int/float/boolean etc). I'll fix it for the next version.
Upupzealot Upupzealot

2014/9/1

#
thanks davmac! :D
efe efe

2014/12/8

#
I seem to have the same problem. I have a scenario using the classes Hallway (subclass of world) Person (subclass of Actor) and Queue (other classes) . The Hallway Class has an instance variable q defined which is of the type Queue. When trying to create a new Queue Object in the constructor of Hallway and try assigning it to q, I get a null pointer exeption when inspecting the Hallway object. Here is the error message: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Using Greenfoot 2.3 I get the same error, however, when I create a method to create the Queue object behaviour is as expected, the Queue object is created and assigned to q. The very same solution doesn't work with Greenfoot 2.4 though, the null pointer exception remains. Using the same setup in BlueJ I get no error in the first place. Is there a way around this or do I have to wait for the next version?
davmac davmac

2014/12/8

#
efe wrote...
Is there a way around this or do I have to wait for the next version?
davmac wrote...
The problem is caused by having any package-private (i.e. not 'public', not 'private') instance variable of reference type (not int/float/boolean etc)
Make your fields public or private.
efe efe

2014/12/9

#
ok, now I got it I actually have to declare the instance variables public or private which I didn't in the first place. With that little modifications things work nicely. Thank's a lot.
You need to login to post a reply.