0

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

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; must be caught or declared to be thrown at jfugue.ParserDemo2.main(ParserDemo2.java:18)

What does this error mean?

David Koelle
  • 20,726
  • 23
  • 93
  • 130

1 Answers1

0

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.

You'll find that parser.parse() also throws a couple of exceptions: ValidityException and 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 {
David Koelle
  • 20,726
  • 23
  • 93
  • 130