Heber Diamond
Heber Diamond

Reputation: 11

JavaFX Media not loading a sound file

I am trying to play a simple sound file using javafx media. Here is my error.

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1135)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.UnsatisfiedLinkError: no glib-lite in java.library.path: /Users/heberdiamond/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2458)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:916)
    at java.base/java.lang.System.loadLibrary(System.java:2063)
    at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:170)
    at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:58)
    at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.lambda$new$0(NativeMediaManager.java:111)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:571)
    at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.<init>(NativeMediaManager.java:108)
    at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager$NativeMediaManagerInitializer.<clinit>(NativeMediaManager.java:78)
    at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.getDefaultInstance(NativeMediaManager.java:90)
    at javafx.media/com.sun.media.jfxmedia.MediaManager.canPlayProtocol(MediaManager.java:78)
    at javafx.media/com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:240)
    at javafx.media/javafx.scene.media.Media.<init>(Media.java:392)
    at Runner.start(Runner.java:17)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application Runner

Here's the code for the media player. It's inside the start method.

import java.io.File;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.stage.Stage;

public class Runner extends Application
{

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        String soundFileName = "sounds/shootSound.wav";
        File  file = new File(soundFileName);
        Media media = new Media(file.toURI().toString());
        
        
        Group root = new Group();
        Scene scene = new Scene(root);
        
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args)
    {
        launch(args);
    }

}

I can't figure out how to get the file to play. I am using eclipse, here's my folders.
the folders of my project

I have tried using file.toURI().getPath() instead, and I jsut get a different error (It says the file is null)

update: I am using macOS sequoia 15.3 beta. I do not know how to find my java and javafx version on eclipse. When creating the project, I used e(fx)clips, and it automatically added all the javafx files. I have done a lot of other things with javafx, and they all worked. This is the only thing that didn't.

Here is my build path:
My build path
All I did was create a blank java project, and javafx just worked.

Upvotes: 1

Views: 52

Answers (0)

Related Questions