Sign in to follow this  
baystep

Java Applet Help (File Loading)

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....

[code]
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();
}
[/code]

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this