Sax Parser没有找到解析

时间:2015-05-18 00:22:03

标签: java sax saxparser saxparseexception

尝试运行以下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)

正如您所看到的,我已经包含了必要的文件但它没有编译。

1 个答案:

答案 0 :(得分:1)

更改

的导入
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

set thePW to "MY_PASSWORD"
set thePane to "Security & Privacy"

activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"
        click menu item thePane of menu "View" of menu bar 1
        delay 3
        if title of button 1 of window 1 is "Click the lock to make changes." then
            click button 1 of window 1
            delay 2
            keystroke thePW
            keystroke return
        end if
    end tell
end tell

解决错误