Public Group

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having an issue with my code right now. I guess I just don't understand the proper procedure for loading external files. What I'm trying to do is write an applet that will load midi files from its jar and play them out.
I want it as an applet so I can embed it, and JAR packaged for ease of transfer and distribution. But I can't get file loading to work. I'm using Eclipse as my IDE, and JRE 1.5. When I test the applet in Eclipse locally it works just fine. Loads the image and midi file and processes the note info. But when I try it outside, either just as a .class file embeded in an html file using the APPLET tag, or Exporting as a Jar.

When I try either one, nothing loads. The loading cursor just goes for awhile and then nothing. I'm guessing this has to do with which form of loading I'm doing. Here's the code that handles the loading. Which right now is my whole init method....

 background = getImage(getCodeBase(),"Assets/background.png"); try { MidiEnum.MIDIDump(new File("Assets\\Midi\\Example.mid")); } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

The MidiEnum class is a static class I created to hold the helper functions so that's not initiated at all. Any ideas? Is there a better process for loading data files? And what would be the best way to handle loading these files from within a jar and using a web URL?

##### Share on other sites
Hi,

first: Did you check for exceptions in the Java console? I'd guess a FileNotFoundException is present, however, please check. (Firefox: Java Console add-on).

Second: If you would like to load resources from a jar, try to use getResourceAsStream from the ClassLoader. See here for starters: http://mindprod.com/jgloss/getresourceasstream.html

If you are using the File constructor, the JVM tries to open the file found at the specified location. It works from inside Eclipse, because the files are physically in these directories. Remove them and it won't work anymore.

Hth,
Philipp

##### Share on other sites
Thanks for the ideas. I will check on that. I almost gave up and went to Flash. But flash doesn't have any native support for MIDI so it would be the loooooooooooooooonnnnnnnnnnggggg road.

##### Share on other sites
Naaah, don't let Java discourage you. It's still a decent language (yeah, arguably -- don't start). As long as you have some fun doing what you do: Go with it...

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
frob
12

• 9
• 17
• 9
• 31
• 16
• ### Forum Statistics

• Total Topics
632617
• Total Posts
3007453

×