-2

I am trying to play a .wav file everytime mouse is pressed down, program starts just fine but when I click on the sprite I get an error, does anyone know whats the problem? I am using IntelliJ, SDK 15

This is the part where I am trying to play the sound

private void onClick() {
        state = 1;
        Game.lowersc();
        AudioClip audioClip = new AudioClip(Paths.get("src/space.wav").toUri().toString());
        audioClip.play(50);
    }

I get this error:

class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x3460c88d) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x3460c88d
Slaw
  • 37,820
  • 8
  • 53
  • 80
Tiny
  • 11
  • 3
  • Well, what is the error? If you get an error it might be -very- handy to know -what- the error is. Some hints: JavaFX of course does not support any file format available. You can check in the `media` package: https://openjfx.io/javadoc/13/javafx.media/javafx/scene/media/package-summary.html Also, this is part of the `javafx.media` module. – leyren Apr 17 '21 at 04:26
  • 1
    Based on the path you're using (`"src/space.wav"`) what you have is not a file but is instead a _resource_. Do not use the standard file APIs to access resources. You should use something (i.e. not necessarily exactly) like `getClass().getResource("/space.wav").toString()`. Though note that you may have other issues than just the way you access the resource. For more information see https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other – Slaw Apr 17 '21 at 07:12
  • class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x3460c88d) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x3460c88d This is the message – Tiny Apr 17 '21 at 09:02
  • some notes for your next question: a) provide a [mcve] demonstrating what's not working as expected b) add clarifications to the question (vs. a comment) – kleopatra Apr 17 '21 at 09:38
  • @LukášPivka I'm glad you managed to find a solution. Based on the error you described I've closed this question as a duplicate. However, my previous comment regarding how you access the resource still stands. – Slaw Apr 17 '21 at 22:46

2 Answers2

1

So it turns out I just forgot to add javafx.media into my VM options, thank you all for my help :D

Tiny
  • 11
  • 3
0

It might be something with packages. I apologize for using this answer space when I don't know definitively, but it's kinda long, and wouldn't fit in a comment. make a file called module-info.java inside src and a package inside src:

src{
   packagename{all your files here}
   module-info.java
}

That's not actual code, it's just how your file structure would look. module-info.java looks like this:

module packagename {
    requires javafx.controls;
    requires javafx.fxml; 
    exports packagename;
}

Replace packagename with the actual name, and requires ___ with the things (? I don't know what to call them) that your project requires. If you don't know, you could keep those, and add others if your IDE says to.

Cole Henrich
  • 155
  • 3
  • 17
  • 1
    Thanks for trying to help but its too late in night here so Ill just call it quits for today and Ill come back tomorrow and let you know if it worked :D , but it will propably be something with packpages – Tiny Apr 16 '21 at 23:22