简体   繁体   English

musicxmlparser错误未报告的异常

[英]musicxmlparser error unreported exception

I am doing my project about software score reader, in this part I want to convert musicxmlparser to staccato/midi but before that I code some 我正在做有关软件乐谱读取器的项目,在这一部分中,我想将musicxmlparser转换为staccato / midi,但在此之前我编写了一些代码

public static void main(String[] args) throws InvalidMidiDataException, IOException {
        MusicXmlParser parser = new MusicXmlParser();
        StaccatoParserListener listener = new StaccatoParserListener();
        parser.addParserListener(listener);
        parser.parse(new File("C:\\Users\\ASUS\\Documents\\Java Project\\ActorPreludeSample.xml"));
    }

and I got error 我有错误

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception javax.xml.parsers.ParserConfigurationException; 线程“主”中的异常java.lang.RuntimeException:无法编译的源代码-未报告的异常javax.xml.parsers.ParserConfigurationException; must be caught or declared to be thrown at jfugue.ParserDemo2.main(ParserDemo2.java:18) 必须在jfugue.ParserDemo2.main(ParserDemo2.java:18)处被捕获或声明为被抛出

What does this error mean? 这个错误是什么意思?

The error is telling you that one of the methods is throwing a ParserConfigurationException (Hint: it's the MusicXmlParser constructor), and you either need to wrap that code in a try/catch block, or throw the code from your main() method's declaration. 错误告诉您方法之一抛出了ParserConfigurationException(提示:这是MusicXmlParser构造函数),您需要将该代码包装在try / catch块中,或者从main()方法的声明中抛出代码。

You'll find that parser.parse() also throws a couple of exceptions: ValidityException and ParsingExcecption. 您会发现parser.parse()也引发了两个异常:ValidityException和ParsingExcecption。

The easiest way to solve this for a simple example is to throw the exceptions in your method declaration: 对于一个简单的示例,解决此问题的最简单方法是在方法声明中引发异常:

public static void main(String[] args) throws InvalidMidiDataException, IOException, ParserConfigurationException, ValidityException, ParsingException {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM