Sax Parser 找不到要解析的方法
Sax Parser No method found to parse
尝试运行下面提到的代码tutorial
一切都完美编译,但它在主要方法中显示错误。
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.jar.Attributes;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import jdk.internal.org.xml.sax.SAXException;
import jdk.internal.org.xml.sax.helpers.DefaultHandler;
public class SaxParserExample {
public static void main (String argv []) {
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
InputStream xmlInput =
new FileInputStream("data\sax-example.xml");
SAXParser saxParser = factory.newSAXParser();
SaxHandler handler = new SaxHandler();
saxParser.parse(xmlInput, handler);
for(Driver driver : handler.drivers){
System.out.println(driver);
}
} catch (Throwable err) {
err.printStackTrace ();
}
}
}
在以下行中:
saxParser.parse(xmlInput, handler);
错误:
error: no suitable method found for parse(InputStream,SaxHandler)
saxParser.parse(xmlInput, handler);
method SAXParser.parse(InputStream,HandlerBase) is not applicable
(argument mismatch; SaxHandler cannot be converted to HandlerBase)
method SAXParser.parse(InputStream,DefaultHandler) is not applicable
(argument mismatch; SaxHandler cannot be converted to DefaultHandler)
method SAXParser.parse(String,HandlerBase) is not applicable
(argument mismatch; InputStream cannot be converted to String)
method SAXParser.parse(String,DefaultHandler) is not applicable
(argument mismatch; InputStream cannot be converted to String)
method SAXParser.parse(File,HandlerBase) is not applicable
(argument mismatch; InputStream cannot be converted to File)
method SAXParser.parse(File,DefaultHandler) is not applicable
(argument mismatch; InputStream cannot be converted to File)
method SAXParser.parse(InputSource,HandlerBase) is not applicable
(argument mismatch; InputStream cannot be converted to InputSource)
method SAXParser.parse(InputSource,DefaultHandler) is not applicable
(argument mismatch; InputStream cannot be converted to InputSource)
如您所见,我已经包含了必要的文件,但它无法编译。
更改来自
的导入
import jdk.internal.org.xml.sax.Attributes;
import jdk.internal.org.xml.sax.SAXException;
import jdk.internal.org.xml.sax.helpers.DefaultHandler;
至
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
解决错误
尝试运行下面提到的代码tutorial 一切都完美编译,但它在主要方法中显示错误。
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.jar.Attributes;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import jdk.internal.org.xml.sax.SAXException;
import jdk.internal.org.xml.sax.helpers.DefaultHandler;
public class SaxParserExample {
public static void main (String argv []) {
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
InputStream xmlInput =
new FileInputStream("data\sax-example.xml");
SAXParser saxParser = factory.newSAXParser();
SaxHandler handler = new SaxHandler();
saxParser.parse(xmlInput, handler);
for(Driver driver : handler.drivers){
System.out.println(driver);
}
} catch (Throwable err) {
err.printStackTrace ();
}
}
}
在以下行中:
saxParser.parse(xmlInput, handler);
错误:
error: no suitable method found for parse(InputStream,SaxHandler)
saxParser.parse(xmlInput, handler);
method SAXParser.parse(InputStream,HandlerBase) is not applicable
(argument mismatch; SaxHandler cannot be converted to HandlerBase)
method SAXParser.parse(InputStream,DefaultHandler) is not applicable
(argument mismatch; SaxHandler cannot be converted to DefaultHandler)
method SAXParser.parse(String,HandlerBase) is not applicable
(argument mismatch; InputStream cannot be converted to String)
method SAXParser.parse(String,DefaultHandler) is not applicable
(argument mismatch; InputStream cannot be converted to String)
method SAXParser.parse(File,HandlerBase) is not applicable
(argument mismatch; InputStream cannot be converted to File)
method SAXParser.parse(File,DefaultHandler) is not applicable
(argument mismatch; InputStream cannot be converted to File)
method SAXParser.parse(InputSource,HandlerBase) is not applicable
(argument mismatch; InputStream cannot be converted to InputSource)
method SAXParser.parse(InputSource,DefaultHandler) is not applicable
(argument mismatch; InputStream cannot be converted to InputSource)
如您所见,我已经包含了必要的文件,但它无法编译。
更改来自
的导入import jdk.internal.org.xml.sax.Attributes;
import jdk.internal.org.xml.sax.SAXException;
import jdk.internal.org.xml.sax.helpers.DefaultHandler;
至
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
解决错误