Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

#6 NullPointerException using JMathComponent in NetBeans forms

closed
nobody
None
5
2007-05-13
2007-05-01
No

Hi,

I added the JMathComponent bean to the palette, so that I can use it to create forms. When I add it to an otherwise empty panel, set the content property to the value shown below and request the preview, I get a NullPointerException related to sizing.

Test formula:

<?xml version="1.0" encoding="UTF-8"?>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>

Exception stack trace:

java.lang.NullPointerException
at net.sourceforge.jeuclid.elements.presentation.token.AbstractTokenWithTextLayout.produceTextLayout(AbstractTokenWithTextLayout.java:94)
at net.sourceforge.jeuclid.elements.presentation.token.AbstractTokenWithTextLayout.calculateWidth(AbstractTokenWithTextLayout.java:121)
at net.sourceforge.jeuclid.elements.AbstractJEuclidElement.getWidth(AbstractJEuclidElement.java:864)
at net.sourceforge.jeuclid.elements.presentation.general.Mfrac.calculateWidth(Mfrac.java:201)
at net.sourceforge.jeuclid.elements.AbstractJEuclidElement.getWidth(AbstractJEuclidElement.java:864)
at net.sourceforge.jeuclid.elements.support.ElementListSupport.getWidth(ElementListSupport.java:128)
at net.sourceforge.jeuclid.elements.generic.DocumentElement.getWidth(DocumentElement.java:88)
at net.sourceforge.jeuclid.MathBase.getWidth(MathBase.java:181)
at net.sourceforge.jeuclid.swing.JMathComponent.getMinimumSize(JMathComponent.java:129)
at org.jdesktop.layout.GroupLayout$ComponentSpring.calculateNonlinkedMinimumSize(GroupLayout.java:2649)
at org.jdesktop.layout.GroupLayout$ComponentSpring.calculateMinimumSize(GroupLayout.java:2613)
at org.jdesktop.layout.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1169)
at org.jdesktop.layout.GroupLayout$ComponentSpring.calculatePreferredSize(GroupLayout.java:2620)
at org.jdesktop.layout.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1179)
at org.jdesktop.layout.GroupLayout$Group.getSpringSize(GroupLayout.java:1353)
at org.jdesktop.layout.GroupLayout$Group.calculateSize(GroupLayout.java:1335)
at org.jdesktop.layout.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1306)
at org.jdesktop.layout.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1179)
at org.jdesktop.layout.GroupLayout$Group.getSpringSize(GroupLayout.java:1353)
at org.jdesktop.layout.GroupLayout$Group.calculateSize(GroupLayout.java:1333)
at org.jdesktop.layout.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1306)
at org.jdesktop.layout.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1179)
at org.jdesktop.layout.GroupLayout$Group.getSpringSize(GroupLayout.java:1353)
at org.jdesktop.layout.GroupLayout$Group.calculateSize(GroupLayout.java:1333)
at org.jdesktop.layout.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1306)
at org.jdesktop.layout.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1179)
at org.jdesktop.layout.GroupLayout$SequentialGroup.setValidSize(GroupLayout.java:1728)
at org.jdesktop.layout.GroupLayout$Group.setSize(GroupLayout.java:1291)
at org.jdesktop.layout.GroupLayout.calculateAutopadding(GroupLayout.java:977)
at org.jdesktop.layout.GroupLayout.layoutContainer(GroupLayout.java:814)
at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.createLayout(SwingLayoutBuilder.java:135)
at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.setupContainerLayout(SwingLayoutBuilder.java:80)
at org.netbeans.modules.form.VisualReplicator.setupContainerLayout(VisualReplicator.java:740)
at org.netbeans.modules.form.VisualReplicator.cloneComponent(VisualReplicator.java:676)
at org.netbeans.modules.form.VisualReplicator.createClone(VisualReplicator.java:177)
at org.netbeans.modules.form.VisualReplicator.createClone(VisualReplicator.java:165)
at org.netbeans.modules.form.FormDesigner$4.run(FormDesigner.java:527)
at org.netbeans.modules.form.FormLAF$1.run(FormLAF.java:150)
at org.openide.util.Mutex.doEventAccess(Mutex.java:1178)
at org.openide.util.Mutex.readAccess(Mutex.java:259)
at org.netbeans.modules.form.FormLAF.executeWithLookAndFeel(FormLAF.java:135)
at org.netbeans.modules.form.FormDesigner.createFormView(FormDesigner.java:521)
at org.netbeans.modules.form.actions.TestAction.run(TestAction.java:119)
at org.netbeans.modules.form.actions.TestAction.performAction(TestAction.java:80)
at org.openide.util.actions.CallableSystemAction$1.run(CallableSystemAction.java:100)
at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:53)
at org.openide.util.actions.CallableSystemAction.actionPerformed(CallableSystemAction.java:96)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
at java.awt.Component.processMouseEvent(Component.java:5501)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at org.openide.awt.ToolbarButton.processMouseEvent(ToolbarButton.java:39)
at java.awt.Component.processEvent(Component.java:5266)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3968)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1778)
at java.awt.Component.dispatchEvent(Component.java:3803)
[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Discussion

  • Erik Putrycz

    Erik Putrycz - 2007-05-01

    Logged In: YES
    user_id=568958
    Originator: NO

    I'd be quite interested to look at that. I'm also using netbeans and JEuclid, but I'm rendenring the result as an picture that I display in a JText component. Do you mind explaining how to add JEuclid to netbeans?

     
  • Michael Rudolf

    Michael Rudolf - 2007-05-01

    Logged In: YES
    user_id=277412
    Originator: YES

    I created a new panel in my project using New -> File/Folder... -> Java GUI Forms -> JPanel Form
    Then I added the JMathComponent bean to the palette by right-clicking on the component palette, choosing "Palette Manager...", "Add From JAR...", selecting the jeuclid JAR file and choosing "JMathComponent". After the bean had been added to the palette, I dragged it onto the panel. One thing that struck me was that the initial size of the component seems to be zero, so I resized the component. Then I set the contents property in the properties window to the value given in the initial bug report. The formula is displayed properly, however the preview does not work.

     
  • Max Berger

    Max Berger - 2007-05-02

    Logged In: YES
    user_id=99210
    Originator: NO

    Michael,

    unfortunately I cannot reproduce the NullPointerException, trying to load the same file into MathViewer seems to work just fine here.

    When you say "the preview does not work", do you mean the preview in netbeans? and when you run your app, everything works just fine?

    The size of an empty Math Component is indeed 0x0. This also results in some Exceptions when trying to render invalid mathml. It is changed to 1x1 in SVN.

    Max

     
  • Michael Rudolf

    Michael Rudolf - 2007-05-03

    Logged In: YES
    user_id=277412
    Originator: YES

    Actually the file is OK. With "preview" I mean the NetBeans form preview. When I close the form and reopen it again, its size is not (re-)stored. Furthermore, the formula is shown in NetBeans but not when I run the application from the command line. I have the feeling that the JMathViewer component ignores the size it is assigned and just computes its own size. In that computation there probably is a bug causing a NullPointerException. Maybe this has something to do with the order in which NetBeans sets up the bean properties. I could imagine that if it first sets up the size and only afterwards assigns the content property, something goes wrong. However, I do not have access to the source code generated by NetBeans at the moment so I cannot tell for sure. What suprises me is that the formula is displayed in NetBeans but not when running the application from the command line.

    Best regards,
    Michael

     
  • Michael Rudolf

    Michael Rudolf - 2007-05-03

    Logged In: YES
    user_id=277412
    Originator: YES

    Hi,

    I had a look at the code NetBeans generated from its XML form description and as far as I can tell it is crashing in between due to some bug in JMathComponent, so that actually the code for adding the components to the content pane is missing. Therefore I could not see anything when running the application from the command line. The same NPE that I described in the initial comment is constantly popping up when I modify the form and thereby force NetBeans to update its generated code.

    As far as I can see the line producing the NPE is

    this.layout = new TextLayout(this.textContentAsAttributedString().getIterator(), g2d.getFontRenderContext());

    That means that either the method textContentAsAttributedString() returns null for one of the two element of the Mfrac or g2d is null. I hope this is useful for hunting down that bug.

    Best regards,
    Michael

     
  • Max Berger

    Max Berger - 2007-05-05
    • status: open --> pending
     
  • Max Berger

    Max Berger - 2007-05-05

    Logged In: YES
    user_id=99210
    Originator: NO

    Interesting. textContentAsAttributedString() should never return null, so the graphics context must be null, which may as well be if NetBeans does some strange behind-the-scenes handling.

    can you please check by adding the following line (or something similar) to the beginning of the JMathComponent.paintComponent() method?

    System.out.println(""+g);

    and see what this gets you?

    Please try this BEFORE and AFTER updating to the most current version. I have implemented the re-serialization code properly, which now fully supports the "getContent" function. This may have had an influence as well.

    Max

     
  • Michael Rudolf

    Michael Rudolf - 2007-05-06

    Logged In: YES
    user_id=277412
    Originator: YES

    Hi,

    In order to do so I checked out the 2.9.6 tag from the subversion repository. However, when trying to build jeuclid maven throws an exception:

    [INFO] Scanning for projects...
    [INFO] ----------------------------------------------------------------------------
    [INFO] Building JEuclid
    [INFO] task-segment: [validate]
    [INFO] ----------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] The plugin 'org.codehaus.mojo:appbundler-maven-plugin' does not exist or no valid version could be found
    [INFO] ------------------------------------------------------------------------
    [INFO] For more information, run Maven with the -e switch
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1 second
    [INFO] Finished at: Sun May 06 21:32:16 CEST 2007
    [INFO] Final Memory: 2M/5M
    [INFO] ------------------------------------------------------------------------

    I am not quite sure how to solve it for I do not have so much maven experience. I remembered reading something about creating an ant build file from the maven project definition but when I try "mvn ant:ant" I get the very same exception.

    Best regards,
    Michael

     
  • Michael Rudolf

    Michael Rudolf - 2007-05-06
    • status: pending --> open
     
  • Michael Rudolf

    Michael Rudolf - 2007-05-13
     
  • Michael Rudolf

    Michael Rudolf - 2007-05-13

    Logged In: YES
    user_id=277412
    Originator: YES

    As nobody seemed to know anything about this strange error message I searched the internet for people with similar problem. However, I could not find very much. Therefore I suppose that something is wrong with my setup. Furthermore, I just tried again and the error does not seem to be transient (e.g. due to a server that was down). So, here is some information about my system, maybe someone is able to tell me what to upgrade/install:

    Maven version: 2.0.6

    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode)

    Linux localhost 2.6.20-gentoo-r5 #1 PREEMPT Sat Apr 14 11:36:46 CEST 2007 i686 Intel(R) Pentium(R) 4 CPU 2.53GHz GenuineIntel GNU/Linux

    I also deleted my user plugin registry but when maven downloads the plugins again it also stops as the appbundler plugin with the same error message. I will attach the output of "mvn -X -e validate".
    File Added: mvn.log

     
  • Max Berger

    Max Berger - 2007-05-13

    Logged In: YES
    user_id=99210
    Originator: NO

    Dear Michael,

    I am terribly sorry, I wasn't monitoring this bug (now done). The error you get is due to maven not being able to find the "appbundler" plugin, which you don't need anyways, as it's only necessary for the OS X applications. Ways to fix this:

    - run mvn with the "-u" option should download it (its in a snapshot repository)
    - edit the pom.xml and delete the plugin definition for appbundler (starting at <plugin>, ending at </plugin>, and of course only the one containing appbundler-maven-plugin.

    Sorry about this, I was promised there would be an appbundler release soon, which should fix this problem.

    Max

     
  • Michael Rudolf

    Michael Rudolf - 2007-05-13

    Logged In: YES
    user_id=277412
    Originator: YES

    The -U option did not work. However, when I removed the plugin reference from the pom file it worked. I tested tag 2.9.6 but to no avail. But the current svn snapshot works without problems. Fantastic!

    There is one more thing: Is there a way to enable font antialiasing? I mean specifically for the mathviewer component, not for the whole system?

    Best regards,
    Michael

     
  • Max Berger

    Max Berger - 2007-05-13
    • status: open --> closed
     

Log in to post a comment.