[OpenMap Users] Problem with BasicI18N

From: Tennessee Leeuwenburg <tjl_at_bom.gov.au>
Date: Thu, 12 May 2005 11:44:05 +1000

Hi all,

I'm getting a weird problem compiling under Java 1.5. It boils down to a
null pointer exception when calling Class.getPackage() on one of the
openamp classes. I think this is happening because the class is getting
loaded at runtime and the package in which it resides is not a part of
the classpath, but that's just a guess, and might not be correct.

The error occurs when I try to load openmap as an applet, although I
don't see why this makes a difference, as the error doesn't *look*
related. The Java console shows this :

network: Connecting
http://localhost/openmap2005/classes/com/bbn/openmap/gui/AddLayer.gif
with proxy=DIRECT
network: Connecting
http://localhost/openmap2005/classes/com/bbn/openmap/gui/AddLayer.gif
with proxy=DIRECT
Requestor: class com.bbn.openmap.gui.LayerControlButtonPanel
Requestor package: null
java.lang.NullPointerException
    at com.bbn.openmap.BasicI18n.getInternal(BasicI18n.java:447)
    at com.bbn.openmap.BasicI18n.get(BasicI18n.java:135)
    at com.bbn.openmap.BasicI18n.get(BasicI18n.java:130)
    at
com.bbn.openmap.gui.LayerControlButtonPanel.createInterface(LayerControlButtonPanel.java:273)
    at
com.bbn.openmap.gui.LayerControlButtonPanel.<init>(LayerControlButtonPanel.java:197)
    at
com.bbn.openmap.gui.LayerControlButtonPanel.<init>(LayerControlButtonPanel.java:201)
    at
com.bbn.openmap.gui.LayersPanel.createControlButtons(LayersPanel.java:641)
    at com.bbn.openmap.gui.LayersPanel.setProperties(LayersPanel.java:999)
    at
com.bbn.openmap.util.ComponentFactory.create(ComponentFactory.java:440)
    at
com.bbn.openmap.util.ComponentFactory.create(ComponentFactory.java:346)
    at
com.bbn.openmap.util.ComponentFactory.create(ComponentFactory.java:298)
    at
com.bbn.openmap.util.ComponentFactory.create(ComponentFactory.java:236)
    at
com.bbn.openmap.util.ComponentFactory.create(ComponentFactory.java:161)
    at
com.bbn.openmap.PropertyHandler.createComponents(PropertyHandler.java:826)
    at
com.bbn.openmap.gui.BasicMapPanel.createComponents(BasicMapPanel.java:170)
    at com.bbn.openmap.gui.BasicMapPanel.create(BasicMapPanel.java:129)
    at com.bbn.openmap.gui.BasicMapPanel.<init>(BasicMapPanel.java:117)
    at com.bbn.openmap.gui.BasicMapPanel.<init>(BasicMapPanel.java:102)
    at com.bbn.openmap.app.OpenMapApplet.init(OpenMapApplet.java:170)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
basic: Exception: java.lang.NullPointerException

The code is slightly modified to include extra debugging. I first saw
the error being caused by what is now line 448. The code snippet is :

442 protected String getInternal(Class requestor, String field, int
type) {
443 ResourceBundle bundle = null;

445 System.out.println("Requestor: " + requestor);
446 System.out.println("Requestor package: " +
requestor.getPackage());
447 System.out.println("Requestor package name: " +
requestor.getPackage().getName());
       
448 String bString = requestor.getPackage().getName() + "." +
ResourceFileNamePrefix;

        try {
            bundle = ResourceBundle.getBundle(bString, loc);
        } catch (MissingResourceException e) {
            Debug.message(DEBUG, "Could not locate resource: "
                    + bString.replace('.', '/') + ".properties");
            return null;
        }

As you can see, the requestor.getPackage() call is returning null. The
class definately is inside a package. The javadoc for Class.getPackage()
is :

public Package <http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Package.html> *getPackage*()

    Gets the package for this class. The class loader of this class is
    used to find the package. If the class was loaded by the bootstrap
    class loader the set of packages loaded from CLASSPATH is searched
    to find the package of the class. Null is returned if no package
    object was created by the class loader of this class.

    Packages have attributes for versions and specifications only if the
    information was defined in the manifests that accompany the classes,
    and if the class loader created the package instance with the
    attributes from the manifest.

    *Returns:*
        the package of the class, or null if no package information is
        available from the archive or codebase

Anyway, I can most likely hack around my problem, but I thought it would
be of general interest, and perhaps other people have some opinion on
what is happening here.

Cheers,
-Tennessee



--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed May 11 2005 - 21:49:25 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:06 EDT