Search Results

Search found 2 results on 1 pages for 'pyroclastic'.

Page 1/1 | 1 

  • Java: Embedding Soundbank file in JAR

    - by Pyroclastic
    If I have a soundbank stored in a JAR, how would I load that soundbank into my application using resource loading...? I'm trying to consolidate as much of a MIDI program into the jar file as I can, and the last thing I have to add is the soundbank file I'm using, as users won't have the soundbanks installed. I'm trying to put it into my jar file, and then load it with getResource() in the Class class, but I'm getting an InvalidMidiDataException on a soundbank that I know is valid. Here's the code, it's in the constructor for my synthesizer object: try { synth = MidiSystem.getSynthesizer(); channels = synth.getChannels(); instrument = MidiSystem.getSoundbank(this.getClass().getResource("img/soundbank-mid.gm")).getInstruments(); currentInstrument = instrument[0]; synth.loadInstrument(currentInstrument); synth.open(); } catch (InvalidMidiDataException ex) { System.out.println("FAIL"); instrument = synth.getAvailableInstruments(); currentInstrument = instrument[0]; synth.loadInstrument(currentInstrument); try { synth.open(); } catch (MidiUnavailableException ex1) { Logger.getLogger(MIDISynth.class.getName()).log(Level.SEVERE, null, ex1); } } catch (IOException ex) { Logger.getLogger(MIDISynth.class.getName()).log(Level.SEVERE, null, ex); } catch (MidiUnavailableException ex) { Logger.getLogger(MIDISynth.class.getName()).log(Level.SEVERE, null, ex); }

    Read the article

  • Java saying XML Document Not Well Formed

    - by Pyroclastic
    Hey all. Java's XML parser seems to be thinking that my XML document is not well formed following the root element, but I've validated it with several tools and they all disagree. It's probably an error in my code rather than in the document itself, I'd really appreciate any help you all could offer me. Here is my Java method: private void loadFromXMLFile(File f) throws ParserConfigurationException, IOException, SAXException { File file = f; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; Document doc = null; db = dbf.newDocumentBuilder(); doc = db.parse(file); doc.getDocumentElement().normalize(); String desc = ""; String due = ""; String comment = ""; NodeList tasksList = doc.getElementsByTagName("task"); for (int i = 0; i < tasksList.getLength(); i++) { NodeList attributes = tasksList.item(i).getChildNodes(); for (int j = 0; i < attributes.getLength(); j++) { Node attribute = attributes.item(i); if (attribute.getNodeName() == "description") { desc = attribute.getTextContent(); } if (attribute.getNodeName() == "due") { due = attribute.getTextContent(); } if (attribute.getNodeName() == "comment") { comment = attribute.getTextContent(); } tasks.add(new Task(desc, due, comment)); } desc = ""; due = ""; comment = ""; } } And here is the XML file I'm trying to load: <?xml version="1.0"?> <tasklist> <task> <description>Task 1</description> <due>Due date 1</due> <comment>Comment 1</comment> <completed>false</completed> </task> <task> <description>Task 2</description> <due>Due date 2</due> <comment>Comment 2</comment> <completed>false</completed> </task> <task> <description>Task 3</description> <due>Due date 3</due> <comment>Comment 3</comment> <completed>true</completed> </task> </tasklist> And here is the error message java is throwing for me: run: [Fatal Error] tasks.xml:28:3: The markup in the document following the root element must be well-formed. May 17, 2010 6:07:02 PM todolist.TodoListGUI SEVERE: null org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208) at todolist.TodoListGUI.loadFromXMLFile(TodoListGUI.java:199) at todolist.TodoListGUI.(TodoListGUI.java:42) at todolist.Main.main(Main.java:25) BUILD SUCCESSFUL (total time: 19 seconds) For reference TodoListGUI.java:199 is doc = db.parse(file); If context is helpful to anyone here, I'm trying to write a simple GUI application to manage a todo list that can read and write to and from XML files defining the tasks. Any advice is appreciated!

    Read the article

1