[jdom-interest] RTFMing didn't work for me

Brett McLaughlin brett.mclaughlin at lutris.com
Thu Sep 7 19:04:00 PDT 2000


David Geller wrote:
> 
> I'm trying the simplest of tests to begin learning JDOM (because I need
> to have a small project running within the next few hours!). So I took a
> look at the sample SAXBuilder on page 209 of Brett's book. BTW - the
> Builder interface doesn't appear to be present in JDOM-4. Anyhow...
> 
> I'm on Linux using IBM's Java2-13. I compile the following code
> *successfully* with:
> 
>    javac -classpath ./jdom-b4.jar:./xerces.jar SAXTest.java

Use the latest version from CVS, it should work fine there.

-Brett

> 
> And I try to run it with:
> 
>    java -cp ./jdom-b4.jar:./xerces.jar:. SAXTest test.xml
> 
> and get:
> 
> org.jdom.JDOMException: String index out of range: 0: String index out
> of range: 0
>         at java.lang.Throwable.<init>(Throwable.java:96)
>         at java.lang.Exception.<init>(Exception.java:44)
>         at org.jdom.JDOMException.<init>(JDOMException.java:101)
>         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:229)
>         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:284)
>         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:265)
>         at SAXTest.main(SAXTest.java:22)
> Root cause: java.lang.StringIndexOutOfBoundsException: String index out
> of range: 0
>         at java.lang.Throwable.<init>(Throwable.java:84)
>         at java.lang.Exception.<init>(Exception.java:35)
>         at org.xml.sax.SAXException.<init>(SAXException.java:61)
>         at
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:834)
>         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:218)
>         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:284)
>         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:265)
>         at SAXTest.main(SAXTest.java:22)
> 
> What am I failing to do/understand? The code, incidentally, is almost
> verbatim from the book - except for the fact that I hardcoded SAXBuilder
> in place of the Builder interface.
> 
> Any help you can provide would be greatly appreciated.
> 
> - David
> 
> Here the test code:
> 
> import java.io.*;
> import org.jdom.Document;
> import org.jdom.Element;
> import org.jdom.JDOMException;
> import org.jdom.input.*;
> 
> public class SAXTest
> {
>         public static void main(String[] args)
>         {
>                 if (args.length != 1)
>                 {
>                         System.out.println ("Usage: SAXTest [filename to
> parse]");
>                         return;
>                 }
> 
>                 try
>                 {
>                         // Build w/ SAX and Xerces, no validation
>                         SAXBuilder b = new SAXBuilder(false);
> 
>                         Document doc = b.build(new File (args[0]));
>                 }
>                 catch (Exception e)
>                 {
>                         e.printStackTrace();
>                 }
>         }
> }

-- 
Brett McLaughlin, Enhydra Strategist
Lutris Technologies, Inc. 
1200 Pacific Avenue, Suite 300 
Santa Cruz, CA 95060 USA 
http://www.lutris.com
http://www.enhydra.org



More information about the jdom-interest mailing list