SAX XML NullPointerException in character() method

I'm having issues when parsing my xml file. Everything works fine unless I am trying to push values into my parameters Vector.

class SAXLoaderextends DefaultHandler{

privatestatic String className,//name of the class for module in xml

methodName,//name of the method for the class

path;//path to jar. should be in URI format

private Vector params;//parameters to the method

privateboolean isClassName,//true if element begins className tag

isMethodName,//true if element begins methodName tag

isParameter,//true if element begins parameter tag

isPath;//true if element begins path tag

//=======================init()================================

//opens XML file specified and parses it for className,

//the methodName,and the path to the JAR

//This should be called before doing any of the getter methods

//=============================================================

publicvoid init(){

try{

XMLReader xmlreader = XMLReaderFactory.createXMLReader();

SAXLoader handler =new SAXLoader();

xmlreader.setContentHandler(handler);

xmlreader.setErrorHandler(handler);

try{

FileReader r =new FileReader("myclass.xml");

xmlreader.parse(new InputSource(r));

}catch (FileNotFoundException e){

System.out.println("File Not Found!");

e.printStackTrace();

}catch (NullPointerException e){

System.out.println("Parse Error!");

e.printStackTrace();

}

}catch (Exception e){

System.out.println("XML Reader Error!");

e.printStackTrace();

}

}

.....

publicvoid characters(char ch[],int start,int length){

String temp ="";

for (int i = start; i < start + length; i++){

switch (ch[i]){

case'\\':

// System.out.print("\\\\");

break;

case'"':

// System.out.print("\\\"");

break;

case'\n':

// System.out.print("\\n");

break;

case'\r':

// System.out.print("\\r");

break;

case'\t':

// System.out.print("\\t");

break;

default:

temp += ch[i];

break;

}

}

if (isClassName){

className = temp;

}elseif (isMethodName){

methodName = temp;

}elseif (isPath){

path = temp;

}elseif (isParameter){

System.out.println("zomg!: " + temp);

params.add(temp);

}

}//end of characters(...

Right there at params.add(temp);

I'm using this DefaultHandler based class to parse an XML file for information regarding a user's own class [its classname, its methodname, and the methods parameters].

Any clues?

Message was edited by:

nick.mancuso

Message was edited by:

nick.mancuso

[5888 byte] By [nick.mancusoa] at [2007-10-3 4:56:13]
# 1

You don't actually allocate the params Vector, at least not on the code you've posted. You want something like:

private Vector params = new Vector();

or better yet:

private List params = new LinkedList();

perhaps.

But even better yet...I suspect that having a handful of global temp variables like that isn't going to work. In my experience, when using SAX you pretty much have to create a stack to hold the current place in the XML tree. That's how you traverse trees, with stacks. Then instead of setting isMethodName, isParameter, etc. (which I presume you do in open/close tag handlers) you define an enumeration of values like "class", "method", "parameter", and then have a stack of those values, or something.

paulcwa at 2007-7-14 23:01:26 > top of Java-index,Java Essentials,Java Programming...