Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Where to park my abc.wav file in the Netbeans IDE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Where to park my abc.wav file in the Netbeans IDE" Watch "Where to park my abc.wav file in the Netbeans IDE" New topic
Author

Where to park my abc.wav file in the Netbeans IDE

Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
I've got a nice little app done with a wav file to make a noise.

Now I'd like to clean & build the whole thing into MyApp.jar with NetBeans.

Problem is.....where do I put my abc.wav file? Must I modify an xml for this?

Kevin Moody
Greenhorn

Joined: Jan 26, 2011
Posts: 2
First create a new Java package like com.dave.elwood.resource.sounds within your main project. Then just copy/paste 'abc.wav' file into that new package.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10375
    
    8

You also need to remember, while access packaged resources in a jar, you should be accessing the using getClass().getResource()


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
Okay, I put my Bang.wav into a seperate package, "Resources"



and this doesn't compile.....what to do??
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10375
    
    8

Dave Elwood wrote:
and this doesn't compile.....what to do??

What error message did you get?
Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
Correction - it compiles and builds but when running this comes out :


the line MyWidgets.MyPanel.makeCrashSound(MyPanel.java:1337) is the line after :


the getResourceAsString(....) returns a null so the next line (line 1337) it hit with NullPointerException

This is a jpg of my resource tree structure



[Thumbnail for Resource Tree.jpg]

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10375
    
    8


Is the file really called resources.bang.wav ? Or is the file situated under resources/bang.wav?

Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
It is this : resources/bang.wav

Here is the real file tree structure....under the folder resources is bang.wav




[Thumbnail for File Structure.jpg]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Dave Elwood wrote:It is this : resources/bang.wav

So use Resources/Bang.wav, not Resources.Bang.wav.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10375
    
    8

Dave Elwood wrote:It is this : resources/bang.wav


What I meant to hint to you was check your code. Are you trying to load the same file in the code?
Do you think Resources.bang.wav and resources/bang.wav are the same?
Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
Do you think Resources.bang.wav and resources/bang.wav are the same?


which one of you told me this? :

First create a new Java package like com.dave.elwood.resource.sounds within your main project. Then just copy/paste 'abc.wav' file into that new package.


it works :
InputStream in = this.getClass().getResourceAsStream("../Resources/Bang.wav");

Thanks guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where to park my abc.wav file in the Netbeans IDE