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

