gpt4 book ai didi

java - java中的SAXParser.parse方法在eclipse Mars中不起作用

转载 作者:行者123 更新时间:2023-11-30 07:41:44 24 4
gpt4 key购买 nike

我按照在线教程创建了 2 个类(子类和主类),通过扩展 DefaultHandler 类来使用 SAX 解析器读取 XML 文件。一切都很好,但是当我尝试在 Eclipse 中编写方法 SAXParser.parse(String URI, DefaultHandler object) 时,它显示以下错误图像。请帮助我,我在这里做错了什么。

Error image

public class mainclass{
public static void main(String []args)
{
DefaultHandler dff=new subclass();
SAXParserFactory spf=SAXParserFactory.newInstance();
try
{
SAXParser sp=spf.newSAXParser();
sp.parse("Trial.xml", dff);
}
catch(Exception e)
{
System.out.println("exception is "+e);
}
}
}

public class subclass extends DefaultHandler{
boolean bheader=false;
boolean bdetail=false;
boolean blpn=false;

public void startDocument() throws SAXException
{
System.out.println("Starting the start document method");
}
public void endDocument() throws SAXException
{
System.out.println("End document method called");
}
public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException
{
System.out.println("Start element method called "+qName);
}
public void endElement(String uri,String localName,String qName) throws SAXException
{
System.out.println("end element method called "+qName);
}
public void characters(char ch[],int start,int length)
{
System.out.println("Characters method called "+new String(ch,start,length));
}
}

最佳答案

您正在从错误的包导入 DefaultHandler 类。你应该导入 org.xml.sax.helpers.DefaultHandler

关于java - java中的SAXParser.parse方法在eclipse Mars中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34574009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com