Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sound?  RSS feed

 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE 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:

 
Stephan van Hulst
Saloon Keeper
Posts: 7808
142
  • 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: 65
Eclipse IDE 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()
 
Dave Tolls
Rancher
Posts: 2914
36
  • 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.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • 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?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • 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: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Website:
Sound
(I tried most of them)
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • 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: 2914
36
  • 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: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh I see!
Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!