首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

用Java写了一个SAX,编译能通过就是不能运行,该怎么处理

2012-02-05 
用Java写了一个SAX,编译能通过就是不能运行大家帮我看看把 感激不尽!Exception in thread main java.lan

用Java写了一个SAX,编译能通过就是不能运行
大家帮我看看把 感激不尽!
Exception in thread "main" java.lang.NoClassDefFoundError:SaxParserGrades

Java code
 
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 code
<?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>


[解决办法]
class SaxParserGrades extends DefaultHandler
这一句是不是应该这样 public class SaxParserGrades extends DefaultHandler

热点排行