用Java写了一个SAX,编译能通过就是不能运行
大家帮我看看把 感激不尽!
Exception in thread "main" java.lang.NoClassDefFoundError:SaxParserGrades
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.xerces.parsers.SAXParser;
class SaxParserGrades extends DefaultHandler
{
static float grades[][] = new float[100][5];
int gi = -1;
int nstudent = 0;
public void startElement(String uri, String localName, String rawName,
Attributes attributes)
{
if(localName.equals("cw1"))
gi = 0;
else if(localName.equals("project"))
gi = 2;
else if(localName.equals("final"))
gi = 3;
else if(localName.equals("student"))
nstudent++;
}
public void endElement(String uri, String localName, String rawName)
{
gi = -1;
}
public void characters(char characters[], int start, int length)
{
String chData = (new String(characters, start, length)).trim();
if(chData.indexOf("\n") < 0 && chData.length() > 0) {
if(gi >= 0){
grades[nstudent-1][gi] = Integer.parseInt(chData);
}
}
}
public void endDocument()
{
float Ave = 0;
int i = 0, j = 0;
System.out.println("Grades");
for(i = 0; i < nstudent ; i++){
float total = 0;
for(j = 0; j < 4; j++){
total += grades[i][j];
}
grades[i][4] = total/4;
Ave += grades[i][4];
System.out.println("Student " + i + "=" + grades[i][4]);
}
Ave /= nstudent;
System.out.println("Class Average = " + Ave);
}
public static void main(String[] args)
{ try{
SaxParserGrades SAXHandler = new SaxParserGrades();
SAXParser parser = new SAXParser();
parser.setContentHandler(SAXHandler);
parser.setErrorHandler(SAXHandler);
parser.parse(args[0]);
}
catch(Exception e){e.printStackTrace(System.err);}
}
}
//javac -classpath "D:\JAVAgo\xerces.jar" SaxParserGrades.java
//java -classpath "D:\JAVAgo\xerces.jar" SaxParserGrades student.xml
<?xml version="1.0"?><course><name id=“CO7204">WTech</name> <teacher id=“srm13"><name>S Reiff-Marganiec</name></teacher><student id=“ah139"><name>Ahmad Hammad</name><cw1>30</cw1><project>80</project><final>85</final></student><student id=“mjs60"><name>Michael Sharpe</name><cw1>80</cw1><project>100</project><final>82</final></student><student id=“wa12"><name>Wesson Altoyan</name><cw1>60</cw1><project>50</project><final>90</final> </student></course>