0

So in order to do part of my assignment I have to use outside files. And I believe I've done this correctly, but I'm still getting an error.

Here is how my project is set up: Eclipse setup

As you can see I'm trying to load the audio 2001.mid and the image nightsky.jpeg. Both of those are located in the resources file inside of project three. I don't see what's wrong, however I'm am completely new to this type of thing. So any help is appreciated.

Also just not note STDdraw is in the lib folder. there is no problem with that either.

This is the error I get when trying to run it.

 Mar 24, 2014 4:00:24 PM java.util.prefs.WindowsPreferences <init>
 WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
 at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
 Exception in thread "main" java.lang.IllegalArgumentException: image
 resources/nightsky.jpeg not found  at
 StdDraw.getImage(StdDraw.java:656)     at
 StdDraw.picture(StdDraw.java:671)  at NBody.main(NBody.java:17)
1
  • You are providing correct path to the file (if of course file is under resources/someFile). If you just want to see how the files works you can e.g. open the text file (by standard library) and print it. However, if you want to play this midi sound or draw something can you provide links to the libraries which you are using? It would be simplier. Commented Mar 24, 2014 at 21:21

2 Answers 2

2

Typically, resources is set up just like src, with the same package structure. You then add both resources and src as source folders in Eclipse.

enter image description here

Now that they are both source folders, the resource files will be copied into your bin folder, right next to the class files that will try to read them. You should then be able to reference them like...

StdAudio.play("2001.mid");  // note, no resources folder prefix
Sign up to request clarification or add additional context in comments.

Comments

-1

I think you are inside one folder(you are in src). So the location of resources is actually here: ../resources

You can check if you have the right path with this code:

File image = new File("../resources/nightsky.jpeg");
        if(image.exists() && !image.isDirectory()) {
             System.out.println("Image found!");

        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.