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.