Skip to main content

[JAVAHELP] NullPointerException in jh2.0

6 replies [Last post]
Anonymous

Hi,

I have the following exception while calling
DefaultHelpBroker.setDisplayed():
java.lang.NullPointerException
at javax.help.WindowPresentation.getSize(WindowPresentation.java:505)
at
javax.help.WindowPresentation.createHelpWindow(WindowPresentation.java:686)
at
javax.help.WindowPresentation.setDisplayed(WindowPresentation.java:328)
at javax.help.DefaultHelpBroker.setDisplayed(DefaultHelpBroker.java:178)
...

This is when I call setDisplayed() from a JDialog as activation window.

Here is a simple code to reproduce (just put a jar file containing
XXXX.hs in classpath):
import javax.help.*;
import javax.swing.*;
import java.net.URL;

class JavaHelpBug extends JDialog {
private DefaultHelpBroker help;

public static void main(String arg[]) {
JDialog d = new JavaHelpBug();
d.setVisible(true);
}

public JavaHelpBug() {
super((JFrame)null, true);
DefaultHelpBroker help = new DefaultHelpBroker();
try {
URL url = ClassLoader.getSystemResource("XXXX.hs");
System.out.println("URL="+url.toString());
help.setHelpSet(new HelpSet(null, url));
help.initPresentation();
help.setActivationWindow(this);
help.setDisplayed(true);
} catch (Exception e) {
e.printStackTrace();
}
}

}

Is anybody have this problem ?
Reading sources, it seems to be a bug in
javax.help.WindowPresentation.getSize() that use the 'dialog' field
before to initialize it.

If someone has a workaround, I will be happy because I cannot show help
from all my dialog box ;-)

--
Christophe GIRARD http://www.solsoft.com KeyID: 0x6097 B5D6
fingerprint: E09F 7D7C 064B 0C62 6C71 E11A EAA0 0A23 6097 B5D6

********************************************************************************

You may leave the list at any time by sending message with no subject and
"SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM. Archives
are available at http://archives.java.sun.com/archives/javahelp-interest.html.
Submit bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Roger Brinkley

Christophe GIRARD wrote:
> Hi,
>
> I have the following exception while calling
> DefaultHelpBroker.setDisplayed():
> java.lang.NullPointerException
> at javax.help.WindowPresentation.getSize(WindowPresentation.java:505)
> at
> javax.help.WindowPresentation.createHelpWindow(WindowPresentation.java:686)
> at
> javax.help.WindowPresentation.setDisplayed(WindowPresentation.java:328)
> at javax.help.DefaultHelpBroker.setDisplayed(DefaultHelpBroker.java:178)
> ...
>
>
> This is when I call setDisplayed() from a JDialog as activation window.
>
> Here is a simple code to reproduce (just put a jar file containing
> XXXX.hs in classpath):
> import javax.help.*;
> import javax.swing.*;
> import java.net.URL;
>
> class JavaHelpBug extends JDialog {
> private DefaultHelpBroker help;
>
> public static void main(String arg[]) {
> JDialog d = new JavaHelpBug();
> d.setVisible(true);
> }
>
> public JavaHelpBug() {
> super((JFrame)null, true);
> DefaultHelpBroker help = new DefaultHelpBroker();
> try {
> URL url = ClassLoader.getSystemResource("XXXX.hs");
> System.out.println("URL="+url.toString());
> help.setHelpSet(new HelpSet(null, url));
> help.initPresentation();
> help.setActivationWindow(this);
> help.setDisplayed(true);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
>
>
> Is anybody have this problem ?
> Reading sources, it seems to be a bug in
> javax.help.WindowPresentation.getSize() that use the 'dialog' field
> before to initialize it.
>
> If someone has a workaround, I will be happy because I cannot show help
> from all my dialog box ;-)
>

Yep it's a bug (id 4924174) with no workaround unfortunately. It crept
in with a bug fix to maintain the size and location of the help window
when help comes and goes. It's been fixed and will appear in the next
release of JavaHelp (2.0.1).

Binky

********************************************************************************

You may leave the list at any time by sending message with no subject and
"SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM. Archives
are available at http://archives.java.sun.com/archives/javahelp-interest.html.
Submit bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.

Christophe GIRARD

On Wed, 2003-09-17 at 22:05, Roger Brinkley wrote:
> Christophe GIRARD wrote:
> > Hi,
> >
> > I have the following exception while calling
> > DefaultHelpBroker.setDisplayed():
> > java.lang.NullPointerException
> > at javax.help.WindowPresentation.getSize(WindowPresentation.java:505)
> > at
> > javax.help.WindowPresentation.createHelpWindow(WindowPresentation.java:686)
> > at
> > javax.help.WindowPresentation.setDisplayed(WindowPresentation.java:328)
> > at javax.help.DefaultHelpBroker.setDisplayed(DefaultHelpBroker.java:178)
> > ...

> Yep it's a bug (id 4924174) with no workaround unfortunately. It crept
> in with a bug fix to maintain the size and location of the help window
> when help comes and goes. It's been fixed and will appear in the next
> release of JavaHelp (2.0.1).
>

Do you know when the 2.0.1 is planned to be released out ?
Because as it was working in the 2.0-rc2, my code was adapted to this
version (waiting the real release), but I cannot distribute it (due to
the evaluation license).

Regards.

--
Christophe GIRARD http://www.solsoft.com KeyID: 0x6097 B5D6
fingerprint: E09F 7D7C 064B 0C62 6C71 E11A EAA0 0A23 6097 B5D6

********************************************************************************

You may leave the list at any time by sending message with no subject and
"SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM. Archives
are available at http://archives.java.sun.com/archives/javahelp-interest.html.
Submit bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.

Roger Brinkley

Christophe GIRARD wrote:

> Do you know when the 2.0.1 is planned to be released out ?
> Because as it was working in the 2.0-rc2, my code was adapted to this
> version (waiting the real release), but I cannot distribute it (due to
> the evaluation license).

Right now we're looking at an October date. Just a quick update to fix
last minute bugs in V2.0.

Binky

********************************************************************************

You may leave the list at any time by sending message with no subject and
"SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM. Archives
are available at http://archives.java.sun.com/archives/javahelp-interest.html.
Submit bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.

magic.finger
Offline
Joined: 2006-02-17
Points: 0

Hello,

I have a quite similar problem with a slightly different exception message under jre 1.4.1_02 and jh v2.0._01 when calling DefaultHelpBroker.setDisplayed() at first from a JDialog and after that from JMenu:

java.lang.IllegalArgumentException: null owner window
at java.awt.Window.ownedInit(Window.java:364)
at java.awt.Window.(Window.java:324)
at java.awt.Dialog.(Dialog.java:313)
at javax.swing.JDialog.(JDialog.java:324)
at javax.swing.JDialog.(JDialog.java:302)
at javax.help.WindowPresentation.createHelpWindow(WindowPresentation.java:737)
at javax.help.WindowPresentation.setDisplayed(WindowPresentation.java:336)
at javax.help.DefaultHelpBroker.setDisplayed(DefaultHelpBroker.java:178)
at de.mycompany.mypackage.MyHelp.dynaHelpBrokerSetDisplayed(MyHelp.java:725)
at de.mycompany.mypackage.MyHelp.showHelp(MyHelp.java:99)
...

Is there any workaround or bug fix available ?

Thanx in advance for any hints and tips !

Maik

Roger Brinkley

java-help@JAVADESKTOP.ORG wrote:
> Hello,
>
> I have a quite similar problem with a slightly different exception message under jre 1.4.1_02 and jh v2.0._01 when calling DefaultHelpBroker.setDisplayed() at first from a JDialog and after that from JMenu:
>
> java.lang.IllegalArgumentException: null owner window
> at java.awt.Window.ownedInit(Window.java:364)
> at java.awt.Window.(Window.java:324)
> at java.awt.Dialog.(Dialog.java:313)
> at javax.swing.JDialog.(JDialog.java:324)
> at javax.swing.JDialog.(JDialog.java:302)
> at javax.help.WindowPresentation.createHelpWindow(WindowPresentation.java:737)
> at javax.help.WindowPresentation.setDisplayed(WindowPresentation.java:336)
> at javax.help.DefaultHelpBroker.setDisplayed(DefaultHelpBroker.java:178)
> at de.mycompany.mypackage.MyHelp.dynaHelpBrokerSetDisplayed(MyHelp.java:725)
> at de.mycompany.mypackage.MyHelp.showHelp(MyHelp.java:99)
> ...
>
> Is there any workaround or bug fix available ?

Looks like your JDialog doesn't have an owner. Is that the case?

Binky

********************************************************************************

You may leave the list at any time by sending message with no subject and
"SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM. Archives
are available at http://archives.java.sun.com/archives/javahelp-interest.html.
Submit bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.

magic.finger
Offline
Joined: 2006-02-17
Points: 0

Hi Binky,

thanks a lot for your answer, but I have provided owner frame to constructor of my override class for JDialog as follows:
public class MyDialog extends JDialog {
public MyDialog(JFrame mainFrame) {
super(mainFrame, true);
hb.enableHelpKey(this, "foo", hs);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
...
}
}
After trying out some workarounds to avoid the null owner window exception I succeed after introducing the method override processWindowEvent() to the dialog class MyDialog.
Since the processWindowEvent() method is always called before windowClosing() WindowListener, which I previously used to capture closing event, now the processWindowEvent() method captures WINDOW_CLOSING event first and calls hide() method of JDialog as last action.
So, the windowClosing() method is not called anymore. And exactly this leads to the fact, that the null owner window exception is also not thrown anymore.

Maybe the owner window handle is (automatically) set to null by Java when windowClosing() method is called ?
I have no idea. Anyway I have a solution right now

Here is the code snippet:
-----------------------------------------
public class MyDialog extends JDialog {

public MyDialog(JFrame mainFrame) {
super(mainFrame, true);
hb.enableHelpKey(this, "foo", hs);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
...
}

protected void processWindowEvent(WindowEvent e) {
// just handle WINDOW_CLOSING event at this point
// instead inside windowClosing listener, which
// is invoked after this method (avoids exception
// thrown by JavaHelp)
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
hide();
}
else {
super.processWindowEvent(e);
}

}
-----------------------------------------

Lucky Maik