2

When attempting to run the following program, an error occurs.

jon@jonathans-mbp-4 lab4 % sysctl -a | grep brand
machdep.cpu.brand_string: Apple M1

jon@jonathans-mbp-4 lab4 % java --version
java 19.0.2 2023-01-17
Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
import javafx.application.Application;

public class App {
    public static void main(String[] args) {
        Application.launch(GUIApplication.class, args);
    }
}

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class GUIApplication extends Application{

    @Override
    public void start(Stage stage) throws Exception {

        // Fix weird font issue in dialog boxes on Macs
        // Application.setUserAgentStylesheet(Application.STYLESHEET_MODENA);        
        // com.sun.javafx.css.StyleManager.getInstance().addUserAgentStylesheet("MainWindow.css");
        
        var loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
        var scene = new Scene(loader.load());

        stage.setScene(scene);
        stage.setTitle("Hello"); // Title of main window
        stage.show();
    }

}
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;


public class MainWindow {

    @FXML
    void onGreetClicked(ActionEvent event) {
        var alert = new Alert(AlertType.INFORMATION, "Hello, world!");
        alert.setHeaderText(null);
        alert.show();

    }
}
.root {
    -fx-padding: 10; /* Add a small padding around the window */
    -fx-font-family: 'Helvetica', Arial, sans-serif;
}

/* for Macs */
.dialog-pane  {
    -fx-font-family: 'Helvetica', Arial, sans-serif;
}
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox fx:controller="MainWindow" xmlns:fx="http://javafx.com/fxml"  stylesheets="@MainWindow.css"
    spacing="10" prefHeight="400" prefWidth="250">

    <Button onAction="#onGreetClicked" text="Greet"  />

</VBox>
jon@jonathans-mbp-4 lab4 % gradle clean install

> Configure project :
Project : => no module-info.java found

BUILD SUCCESSFUL in 782ms
6 actionable tasks: 6 executed
jon@jonathans-mbp-4 lab4 % gradle clean run

> Configure project :
Project : => no module-info.java found

> Task :run FAILED
Loading library prism_es2 from resource failed: java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_es2.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_es2.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_es2.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_es2.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
        at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
        at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
        at java.base/java.lang.Runtime.load0(Runtime.java:755)
        at java.base/java.lang.System.load(System.java:1953)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.installLibraryFromResource(NativeLibLoader.java:217)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryFromResource(NativeLibLoader.java:197)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:138)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:54)
        at javafx.graphics/com.sun.prism.es2.ES2Pipeline.lambda$static$0(ES2Pipeline.java:63)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at javafx.graphics/com.sun.prism.es2.ES2Pipeline.<clinit>(ES2Pipeline.java:52)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:375)
        at javafx.graphics/com.sun.prism.GraphicsPipeline.createPipeline(GraphicsPipeline.java:218)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:92)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
        at java.base/java.lang.Thread.run(Thread.java:833)
Loading library prism_sw from resource failed: java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_sw.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_sw.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_sw.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_sw.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
        at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
        at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
        at java.base/java.lang.Runtime.load0(Runtime.java:755)
        at java.base/java.lang.System.load(System.java:1953)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.installLibraryFromResource(NativeLibLoader.java:217)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryFromResource(NativeLibLoader.java:197)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:138)
        at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:54)
        at javafx.graphics/com.sun.prism.sw.SWPipeline.lambda$static$0(SWPipeline.java:43)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at javafx.graphics/com.sun.prism.sw.SWPipeline.<clinit>(SWPipeline.java:42)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:375)
        at javafx.graphics/com.sun.prism.GraphicsPipeline.createPipeline(GraphicsPipeline.java:218)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:92)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
        at java.base/java.lang.Thread.run(Thread.java:833)
Graphics Device initialization failed for :  es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:283)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:254)
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:264)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:291)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:163)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:659)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:679)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:95)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
        ... 1 more
Exception in thread "main" java.lang.RuntimeException: No toolkit found
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:276)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:291)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:163)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:659)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:679)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base/java.lang.Thread.run(Thread.java:833)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/opt/homebrew/Cellar/openjdk@17/17.0.6/libexec/openjdk.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 777ms
5 actionable tasks: 5 executed

I have run the program from java to install Java 19 (my understanding is that uninstalls previous versions) and nothing changed. I manually deleted the JDKs (/Library/Java/JavaVirtualMachines) and reinstalled jdk-19.jdk.

If it's not obvious, I don't really know what I'm doing. I need to get JavaFX to work for a university lab.

The only other question I found said to reinstall Java, which I believe I did, but didn't fix the issue.

Jon
  • 63
  • 5
  • 1
    Did you find [this](https://stackoverflow.com/a/53994717/14577449) answer already? Maybe it helps your case. – Juhuja Feb 03 '23 at 15:08
  • 3
    not on mac, so a bit of guessing: the error _mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'_ seems to tell you what's wrong .. make sure to follow the instructions of https://openjfx.io/openjfx-docs/ – kleopatra Feb 03 '23 at 15:09
  • JDK11 and onwards removes JavaFX from the JDK. you have to declare it as explicit dependency. – Simulant Feb 03 '23 at 15:15
  • Use a recent version of JavaFX (19+). Most older versions either don’t have M processor support, or that support is broken. – jewelsea Feb 03 '23 at 15:30
  • Provide the gradle build script in the question. Where did the libraries at `.openjfx/cache/17` come from and how did they get there? – jewelsea Feb 03 '23 at 15:34
  • If I wanted to use JavaFX with a clean install of Java (ie from https://download.oracle.com/java/19/latest/jdk-19_macos-aarch64_bin.dmg), how would I install JavaFX? – Jon Feb 03 '23 at 15:44
  • 1
    @Jon to use JavaFX with Oracle JDK, you would follow the instructions at open.jfx.io linked earlier by kleopatra (substituting Oracle JDK for OpenJDK). – jewelsea Feb 03 '23 at 16:09
  • 2
    Alternatively, you can just use *IntelliJ* by JetBrains. That IDE can download and install a JDK from your choice of several vendors. And that IDE offers a template specially for starting a new project for a JavaFX (OpenJFX) app. You can create and run a new JavaFX app in less than a minute. (No need for *brew* in this scenario.) – Basil Bourque Feb 03 '23 at 16:23

1 Answers1

2

Just found this

I installed this

Not sure that this was the best solution (I don't really know what Azul is), but the program runs at least.

Jon
  • 63
  • 5
  • 2
    [Azul Systems](https://en.wikipedia.org/wiki/Azul_Systems) is one of several vendors that provide binaries and installers for a [JDK](https://en.wikipedia.org/wiki/Java_Development_Kit). Other such companies: Amazon, Microsoft, BellSoft, Red Hat, IBM, Oracle, SAP, and more. Of those, two vendors provide an edition of their JDK product that comes bundled with the *OpenJFX* libraries you need to build and run a JavaFX app: *Azul Systems* and *BellSoft*. Alternatively, you can bundle a copy of the *OpenJFX* libraries within your JavaFX app. – Basil Bourque Feb 03 '23 at 16:02
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 05 '23 at 20:04