Home : NullPointerException when Working with ActiveX Controls
Q30945 - ERRMSG: NullPointerException when Working with ActiveX Controls

NullPointerException when Working with ActiveX Controls

When working with ActiveX controls, the control must first be displayed before invoking methods on it. If the control is not displayed first, often you will get a NullPointerException.

As an example, if com.activex.MapControl is an ActiveX component, doing something like this may cause a Null-pointer Exception:

com.activex.MapControl mapcontrol = new com.activex.MapControl();
mapcontrol.zoomIn(); // causes java.lang.NullPointerException

In this case, you may have to display the ActiveX component first, as below:

com.activex.MapControl mapcontrol = new com.activex.MapControl();

// code to display the MapControl should be placed here:
JFrame frame = new JFrame();
frame.setSize(400, 300);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(mapcontrol, BorderLayout.CENTER);
frame.setVisible(true);

mapcontrol.zoomin(); // now it works

Notes:

(1) Actually, not all methods will cause a NullPointerException when called before the ActiveX control is displayed. Any setXX() method can be called beforehand. These setXX() methods will be queued up and automatically called once the ActiveX control is made visible.

(2) ActiveX controls hosted by J-Integra extend com.linar.jintegra.Ocx, which in turn extends java.awt.Canvas (see the generated proxies for details). All java.awt.Canvas components have a property called preferredSize. The preferredSize of any ActiveX control that is hosted by J-Integra defaults to 100x100. This means that whenever the ActiveX control is repainted, its size becomes 100x100. If you wish to change the preferredSize of one of your ActiveX controls, use the JINTEGRA_PREFERRED_SIZE_classname=HH,WW property:

    e.g. java -DJINTEGRA_PREFERRED_SIZE_com.activex.MapControl=400,300 MyClass

* There is a patch for v2.6 which allows the preferredSize of an ActiveX control to change whenever setSize() is called on the control in your Java code. When setSize() is called, the preferredSize becomes whatever height and width was passed to setSize(). If you wish to have this patch, please contact support.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 8/17/2006.
Last Modified by J-Integra KB Admin.
Article has been viewed 10749 times.
Rated 5 out of 10 based on 56 votes.
Print Article
Email Article