xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kenneth B. Harwood" <run10ks...@comcast.net>
Subject loadSVGDocument generates NullPointerException
Date Mon, 15 Aug 2005 20:57:08 GMT
Problem solved.

loadSVGDocument() generates a call to the XML parser (component).
According to the (Class XMLResourceDescriptor) docs, if an XML parser
has not been explicitly set, Batik will attempt to assign one based on
the entry in the resources/XMLResourceDescriptor.properties file.

Although Batik installs this .properties file on my machine,  unlike a
java application, *** an applet cannot read local files (such as 
.properties) without explicit permission (ie. granted in the .policy file). 
***  This caused my XMLParserClassName field to be uninitialized (it 
was NULL), which lead to the NPE.  btw, there is also a 
CSSParserClassName field that has to be set to avoid the same kind 
of error.

I added the following two statements to my class's constructor:


Works like a charm.

 - Ken H.
  ----- Original Message ----- 
  From: Kenneth B. Harwood 
  To: batik-users@xmlgraphics.apache.org 
  Sent: Saturday, August 13, 2005 11:34 PM
  Subject: Fw: loadSVGDocument generates NullPointerException

  Wishful thinking.  I took out all of the Thread stuff; 
  almost running barebones. I'm still having the same 
  NPE problem.

  Take a look that this abbreviated StackTrace (full
  trace available below):

   at java.util.Properties$LineReader.readLine(Unknown Source)
   at java.util.Properties.load(Unknown Source)
   at org.apache.batik.util.XMLResourceDescriptor.getParserProps(Unknown Source)
   at org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName(Unknown Source)
   at org.apache.batik.swing.svg.JSVGComponent$BridgeUserAgent.getXMLParserClassName(Unknown
   at org.apache.batik.swing.svg.JSVGComponent$BridgeUserAgentWrapper.getXMLParserClassName(Unknown
   at org.apache.batik.bridge.DocumentLoader.<init>(Unknown Source)
   at org.apache.batik.swing.svg.JSVGComponent$1.run(Unknown Source)
   at org.apache.batik.swing.svg.JSVGComponent.stopThenRun(Unknown Source)
   at org.apache.batik.swing.svg.JSVGComponent.loadSVGDocument(Unknown Source)  <<<<<<<<<

  I am running this JSVGCanvas inside an Applet.  Oddly, my SVG 
  file loads just fine when I run the same code as an application.  

    From: Kenneth B. Harwood 
    Sent: Thursday, August 11, 2005 1:46 PM

    My system configuration:

    Batik 1.6
    J2SE 5.0/JApplet
    Windows 2K Pro

    Problem description:

    I create a JSVGCanvas, initially "blank" (no SVG file
    displayed) then I put the instance in a new thread.
    I then start() the Thread.  Each time my program 
    reaches the following block:

    public void run() {
          try {
                jSVGCanvas.loadSVGDocument("http://www.mydomain.com/default.svg"); //NPE THROWN
            } catch (Exception expn) {
                System.out.println("Error loading SVG file.");


    I get a NullPointerException.  Here's the entire stackTrace:

     at com.mydomain.run(myclass.java:38)
     at java.lang.Thread.run(Unknown Source)

    I catch the Exception so I continue on.  What happens next 
    depends on my mouse clicks.  For example, after experiencing
    a ModifyThreadGroup error (a problem for another day) I *can* 
    get my SVG file to appear.  After that, I can even load a different 
    SVG file in response to a Menu click (see below).

    Sometimes, depending on my mouse click sequence, when I try 
    to load an SVG in response to a Menu Action, I get this sort of 
    lengthy NPE error:

View raw message