Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Sound?

 
Ranch Hand
Posts: 146
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to know if there is anything wrong with because the console only prints 'null'.
Here is my code:

 
Saloon Keeper
Posts: 12163
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when you perform e.printStackTrace() instead?

Why are you starting a sound clip in a new thread?

Why are you prepending "src/" and appending url to your resource name?
 
Bod McLeon
Ranch Hand
Posts: 146
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What happens when you perform e.printStackTrace() instead?

Why are you starting a sound clip in a new thread?

Why are you prepending "src/" and appending url to your resource name?


Letting you know I got this off of a website :P.
And also can you list the lines that you mean.
Line 'x' needs e.printStackTrace()
 
Rancher
Posts: 4623
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This String (on line 19):
"src/Kevin MacLeod ~ In the Hall of the Mountain King.wav" + url

will produce this value:
"src/Kevin MacLeod ~ In the Hall of the Mountain King.wavnull"

since url is never set to anything other than null.
So I'm guessing that's not what you want.
 
Marshal
Posts: 69884
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us where that code comes from, so we can tell how old the website is; there is something out of date abut using applets. What is the sun.applet package? That sounds suspect. Have you got a .jar with the .wav file in?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove line 1, the import of class sun.applet.Main. I suspect you copied and pasted (part of) this code out of some super-old tutorial about applets. Applets are obsolete (they were cool in 1997...).

Remove all the stuff that has to do with creating and starting a new thread. You don't need that, you're not creating an applet here. Remove lines 14, 15, 25 and 26.

Then, about loading the sound clip. Instead of using getResourceAsStream it's easier to just use a FileInputStream, which you can pass the exact location of the sound file.

You don't need the url variable.

It will all become easier, and especially understanding what error messages mean and understanding why it's not doing what you want it to do, when you carefully read the source code and make sure that you understand what the purpose of each statement is. If you just copy and paste an example or some statements out of some other program and you don't understand exactly how it works and what's happening, then it will be really hard to write a program that does exactly what you want it to do.
 
Bod McLeon
Ranch Hand
Posts: 146
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Website:
Sound
(I tried most of them)
 
Master Rancher
Posts: 3882
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The resource was probably used instead of via a File because the code could then run from a jar file that held the sound file.
 
Dave Tolls
Rancher
Posts: 4623
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bod McLeon wrote:The Website:
Sound
(I tried most of them)



OK, well that is a method that takes a url parameter which is presumably the root under the sounds "directory" to the file required.

You have simply created a local variable and set it to null.

If you just want to open a specific file then get rid of the url variable.
 
Bod McLeon
Ranch Hand
Posts: 146
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh I see!
Thanks!
 
    Bookmark Topic Watch Topic
  • New Topic