求救:SAXParserFactory saxFact = SAXParserFactory.newInstance();错误 不会吧,我刚刚接触xml,这个问题这么难??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你的java and xml 源文件贴出来 <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><!DOCTYPE WBServer SYSTEM "wbserver.dtd"><WBServer id="test"> <Class id="computer" max_group="32"> <Group id="nudt" basedir="data\computer\nudt\" issue_mode="teach" max_client="20" max_lock_time="1" max_user="256" max_page="256"> <Teacher id="sam" password="123"/> <Teacher id="ssg2" password="123"/> <Student id="wave" password="123"/> <Student id="coco" password="123"/> <Student id="foo" password="123"/> <Student id="hehe" password="123"/> <Student id="kang" password="123"/> <Student id="icestar" password="123"/> <Student id="uzcce" password="123"/> <Student id="kiki" password="123"/> <Student id="mudu" password="123"/> <Student id="half" password="123"/> </Group> <Group id="tsh" basedir="data\computer\tsh\" issue_mode="teach" max_client="2" max_lock_time="5" max_user="256" max_page="256"> <Teacher id="don" password="123"/> <Student id="wave" password="123"/> <Student id="half" password="123"/> </Group> </Class> </WBServer>import java.util.Hashtable;import java.util.Vector;import java.util.Enumeration;import java.io.IOException;import java.io.Serializable;import java.io.File;import java.io.FileOutputStream;import java.io.PrintStream;import java.net.ServerSocket;import java.net.Socket;import java.sql.DriverManager;import java.sql.Connection;import java.sql.Statement;import java.sql.ResultSet;import java.sql.SQLException;import javax.swing.JPanel;import javax.swing.BorderFactory;import javax.swing.JSplitPane;import javax.xml.parsers.SAXParserFactory;import javax.xml.parsers.SAXParser;import org.xml.sax.Attributes;import org.xml.sax.XMLReader;import org.xml.sax.ErrorHandler;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.helpers.DefaultHandler;public class readxml extends DefaultHandler implements Serializable,ErrorHandler{ public static final int LOGIN_OK = 0; public static final int LOGIN_FAIL = 1; public static final int LOGIN_ALREADY = 2; JSplitPane pane; int Port = 1701; int Max_Class_Num = 10; int Max_Client_Num = 100; int Kick_Free_Time = 10; String dbDriver = "org.gjt.mm.mysql.Driver"; String dbUser; String dbPassword; // DataBase Connection format jdbc:mysql://hostname/dbname String connStr = "jdbc:mysql://172.26.2.44/wb?user=wb&password=whiteboard"; Vector hClasses; Vector hClients; ServerSocket lsnSock; boolean run_f = false; Connection dbConn; Thread thisThread; public readxml(){ } public void readConfigFile(String filename){ try{ readConfigFile(new File(filename)); }catch(Exception e){ e.printStackTrace(); } } public void readConfigFile(File file){ System.out.println("file is: "+file); SAXParserFactory saxFact = SAXParserFactory.newInstance(); saxFact.setValidating(true); try{ XMLReader xmlReader = saxFact.newSAXParser().getXMLReader(); xmlReader.setContentHandler(this); xmlReader.setErrorHandler(this); xmlReader.parse(file.toURL().toString()); }catch(Exception e){ System.out.println("******error********"); e.printStackTrace(); } } private String getParseExceptionInfo(SAXParseException spe) { String systemId = spe.getSystemId(); if (systemId == null) { systemId = "null"; } String info = "URI=" + systemId + " Line=" + spe.getLineNumber() + ": " + spe.getMessage(); return info; } public void warning(SAXParseException spe)throws SAXException{ System.out.println("Warning: "+getParseExceptionInfo(spe)); } public void error(SAXParseException spe)throws SAXException{ throw new SAXException("Error: "+getParseExceptionInfo(spe)); } public void fatalError(SAXParseException spe)throws SAXException{ throw new SAXException("Fatal Error: "+getParseExceptionInfo(spe)); } public void startDocument()throws SAXException{ System.out.println("XML startDocument"); } public void endDocument()throws SAXException{ } public static int getInt(String s){ return (new Integer(s)).intValue(); } public static String getStr(String s){ try{ return new String(s.getBytes("ISO8859-1")); }catch(Exception e){ e.printStackTrace(); return "ERROR"; } } public void startElement(String nsURI,String localName,String rawName,Attributes atts)throws SAXException{ if (localName.equals("WBServer")){ Port = getInt(atts.getValue("port")); Max_Class_Num = getInt(atts.getValue("max_class")); Max_Client_Num = getInt(atts.getValue("max_client")); dbDriver = atts.getValue("JDBCDriver"); connStr = atts.getValue("url");//+"?user="+atts.getValue("user")+"&password="+atts.getValue("password"); dbUser = atts.getValue("user"); dbPassword = atts.getValue("password"); hClasses = new Vector(Max_Class_Num); hClients = new Vector(Max_Client_Num); }else if (localName.equals("Class")){ hClasses.add( getStr(atts.getValue("id")) ); System.out.println(getStr(atts.getValue("id")) ); }else if (localName.equals("Group")){ System.out.println(getStr(atts.getValue("id"))); }else if (localName.equals("Teacher")){ System.out.println(getStr(atts.getValue("id"))); }else if (localName.equals("Student")){ System.out.println(getStr(atts.getValue("id"))); } } public void endElement(String uri,String localName,String qName)throws SAXException{ if (localName.equals("Class")){ }else if (localName.equals("Group")){ }else if (localName.equals("Teacher")){ }else if (localName.equals("Student")){ } } public static void main(String argv[]){ System.out.println("hi allllll"); readxml rx = new readxml(); rx.readConfigFile("wbserver.xml"); } }编译通过,连“hi allllll”都打印不出来. 不会呀,我编译通过,“hi allllll”还是打印出来了.还打印了下面两句:file is: wbserver.xmlXML startDocument后面出错了. friendy(),你的环境是怎样的?我的是,jdk1.3, jre1.3.1, 还有就是从sun上下载的三个关于xml的jar包,crimson.jar, jaxp.jar, xalan.jar.windows 2000 java可以拿到视频文件的“持续时间”吗 大家谈谈JavaFX在UI方面能发挥出什么作用?? 对正则表达式中包含*的,如何使用分组?? 请各位高手指教! 谢谢~~ 请求大家帮助 about variable range in gui 用递归生成树 FT,请教关于类的protected问题??? 在線等待 關羽修改文件的程序 关于界面动态多个控件的问题 关于java类库的问题 一个非常简单的问题? 菜鸟级问题一个,愿者请进。 jb5的jdk似乎运行rmi有点问题,同时那位的jb5的注册吗有效?
<!DOCTYPE WBServer SYSTEM "wbserver.dtd">
<WBServer id="test">
<Class id="computer" max_group="32">
<Group id="nudt" basedir="data\computer\nudt\" issue_mode="teach" max_client="20" max_lock_time="1" max_user="256" max_page="256">
<Teacher id="sam" password="123"/>
<Teacher id="ssg2" password="123"/> <Student id="wave" password="123"/>
<Student id="coco" password="123"/>
<Student id="foo" password="123"/>
<Student id="hehe" password="123"/>
<Student id="kang" password="123"/>
<Student id="icestar" password="123"/>
<Student id="uzcce" password="123"/>
<Student id="kiki" password="123"/>
<Student id="mudu" password="123"/>
<Student id="half" password="123"/> </Group>
<Group id="tsh" basedir="data\computer\tsh\" issue_mode="teach" max_client="2" max_lock_time="5" max_user="256" max_page="256">
<Teacher id="don" password="123"/> <Student id="wave" password="123"/>
<Student id="half" password="123"/> </Group>
</Class>
</WBServer>import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.io.IOException;
import java.io.Serializable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JSplitPane;import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.Attributes;
import org.xml.sax.XMLReader;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
public class readxml extends DefaultHandler implements Serializable,ErrorHandler{ public static final int LOGIN_OK = 0;
public static final int LOGIN_FAIL = 1;
public static final int LOGIN_ALREADY = 2;
JSplitPane pane;
int Port = 1701;
int Max_Class_Num = 10;
int Max_Client_Num = 100;
int Kick_Free_Time = 10;
String dbDriver = "org.gjt.mm.mysql.Driver";
String dbUser;
String dbPassword;
// DataBase Connection format jdbc:mysql://hostname/dbname
String connStr = "jdbc:mysql://172.26.2.44/wb?user=wb&password=whiteboard";
Vector hClasses;
Vector hClients;
ServerSocket lsnSock;
boolean run_f = false;
Connection dbConn;
Thread thisThread;
public readxml(){
}
public void readConfigFile(String filename){
try{
readConfigFile(new File(filename));
}catch(Exception e){
e.printStackTrace();
}
}
public void readConfigFile(File file){
System.out.println("file is: "+file);
SAXParserFactory saxFact = SAXParserFactory.newInstance();
saxFact.setValidating(true);
try{
XMLReader xmlReader = saxFact.newSAXParser().getXMLReader();
xmlReader.setContentHandler(this);
xmlReader.setErrorHandler(this);
xmlReader.parse(file.toURL().toString());
}catch(Exception e){
System.out.println("******error********");
e.printStackTrace();
}
}
private String getParseExceptionInfo(SAXParseException spe) {
String systemId = spe.getSystemId();
if (systemId == null) {
systemId = "null";
}
String info = "URI=" + systemId +
" Line=" + spe.getLineNumber() +
": " + spe.getMessage();
return info;
}
public void warning(SAXParseException spe)throws SAXException{
System.out.println("Warning: "+getParseExceptionInfo(spe));
}
public void error(SAXParseException spe)throws SAXException{
throw new SAXException("Error: "+getParseExceptionInfo(spe));
}
public void fatalError(SAXParseException spe)throws SAXException{
throw new SAXException("Fatal Error: "+getParseExceptionInfo(spe));
}
public void startDocument()throws SAXException{
System.out.println("XML startDocument");
}
public void endDocument()throws SAXException{
}
public static int getInt(String s){
return (new Integer(s)).intValue();
}
public static String getStr(String s){
try{
return new String(s.getBytes("ISO8859-1"));
}catch(Exception e){
e.printStackTrace();
return "ERROR";
}
}
public void startElement(String nsURI,String localName,String rawName,Attributes atts)throws SAXException{
if (localName.equals("WBServer")){
Port = getInt(atts.getValue("port"));
Max_Class_Num = getInt(atts.getValue("max_class"));
Max_Client_Num = getInt(atts.getValue("max_client"));
dbDriver = atts.getValue("JDBCDriver");
connStr = atts.getValue("url");//+"?user="+atts.getValue("user")+"&password="+atts.getValue("password");
dbUser = atts.getValue("user");
dbPassword = atts.getValue("password"); hClasses = new Vector(Max_Class_Num);
hClients = new Vector(Max_Client_Num);
}else if (localName.equals("Class")){
hClasses.add( getStr(atts.getValue("id")) );
System.out.println(getStr(atts.getValue("id")) );
}else if (localName.equals("Group")){
System.out.println(getStr(atts.getValue("id")));
}else if (localName.equals("Teacher")){
System.out.println(getStr(atts.getValue("id")));
}else if (localName.equals("Student")){
System.out.println(getStr(atts.getValue("id")));
}
}
public void endElement(String uri,String localName,String qName)throws SAXException{
if (localName.equals("Class")){
}else if (localName.equals("Group")){
}else if (localName.equals("Teacher")){
}else if (localName.equals("Student")){
}
}
public static void main(String argv[]){
System.out.println("hi allllll");
readxml rx = new readxml();
rx.readConfigFile("wbserver.xml");
}
}编译通过,连“hi allllll”都打印不出来.
还打印了下面两句:
file is: wbserver.xml
XML startDocument
后面出错了.
我的是,jdk1.3, jre1.3.1, 还有就是从sun上下载的三个关于xml的jar包,
crimson.jar, jaxp.jar, xalan.jar.
windows 2000