UnsatisfiedLinkError with javafx - javafx

I am trying do learn javafx. I have a very simple program to print "Hello World" once in the main method (as a test) and once in the Application. The code looks like this:
import javafx.stage.*;
import javafx.application.*;
public class HelloApp extends Application
{
public static void main(String[] args)
{
System.out.println("Hello World");
launch(args);
}
public void start(Stage stage)
{
System.out.println("Hello World");
}
}
this gives me the following output. Note that it prints the first "Hello World", but not the second.
--------------------Configuration: javafx trials - JDK version 1.6.0_07 <Default> - <Default>--------------------
Hello World
Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\Documents and Settings\apcs.LGSUHSD\My Documents\JCreator LE\MyProjects\bin\glass.dll
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:281)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:124)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:163)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:\Documents and Settings\apcs.LGSUHSD\My Documents\JCreator LE\MyProjects\bin\glass.dll
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1650)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1005)
at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoader.java:200)
at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:88)
at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:31)
at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:73)
at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:80)
at com.sun.glass.ui.win.WinApplication$1.run(WinApplication.java:36)
at com.sun.glass.ui.win.WinApplication$1.run(WinApplication.java:33)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.glass.ui.win.WinApplication.<clinit>(WinApplication.java:33)
at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:20)
at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:17)
at com.sun.glass.ui.Application.Run(Application.java:103)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:271)
... 5 more
Process completed.
I have no Idea why this is happening. I have the jar file for javafx in the project. Can someone please explain why this is happening and what I can do about it?

if you are using eclipse add C:\Program Files\Oracle\JavaFX Runtime\lib\jfxrt.jar as external jar and rebuild project.

Related

Why do I get a constructor exception on JavaFX?

Based on some online reference, I try to bring up a JavaFX applicaion with the simple following code.
#SpringBootApplication
public class DesktopApplication {
public static void main(String[] args) {
Application.launch(ChartApplication.class, args);
}
}
public class ChartApplication extends Application {
#Override
public void start(Stage stage) {
}
}
I can't start up the app due to an error
me#USAUS desktop % java -jar target/desktop-0.0.1-SNAPSHOT.jar
Aug 18, 2022 4:10:10 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module #69ec05a2'
Aug 18, 2022 4:10:15 PM com.sun.glass.ui.mac.MacApplication ambda$waitForReactivation$6
WARNING: Timeout while waiting for app reactivation
Exception in Application constructor
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class com.example.desktop.ChartApplication
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:891)
at 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.NoSuchMethodException: com.example.desktop.ChartApplication.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3585)
at java.base/java.lang.Class.getConstructor(Class.java:2271)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
I don't get why the class can't get constructed.
I use Java 17 and try various version of OpenJfx (versions from 18.0.2, 19 EA and 20 EA), and Spring Boot (2.7.3, 3.0.0-M4) with the same exception.
The cause is that JavaFX is removed from JDK after Java 11.

TestNG, JavaFX Intellij An error occurred while instantiating class, Unable to make public <test class> accessible

I tried to call the test class programmatically and follow the instructor in the TestNG docs. When i called it in Eclipse, it worked, but when i switch to Intellij to be more convenient to use JavaFX so that i can make a UI program, it doesn't work and show this error.
This is my test call class
package com.vinh.testing.CallTest;
import org.testng.TestListenerAdapter;
import org.testng.TestNG;
import tests.LogOutTest;
public class TestLogOutCall {
public void callLogOutTest() {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { LogOutTest.class });
testng.addListener(tla);
testng.run();
}
}
and this is my test class
package tests;
import static io.restassured.RestAssured.*;
import static org.testng.Assert.assertNotEquals;
import org.testng.annotations.Test;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
public class LogOutTest {
String ACCESS_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hdWN0aW9uLWFwcDMuaGVyb2t1YXBwLmNvbVwvYXBpXC9sb2dpbiIsImlhdCI6MTY1NTUzNzg2OSwiZXhwIjoxNjU1ODk3ODY5LCJuYmYiOjE2NTU1Mzc4NjksImp0aSI6InJuejdrMHhSQmNUTHB2TnkiLCJzdWIiOjY1LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.sX-pWrwDyGfCIhlqy_1huxTt3GSElXrQtnpKV53q4BM";
#Test
public void Test01() {
baseURI = "https://auction-app3.herokuapp.com/api";
Response response = given().
header("Authorization", "bearer" + ACCESS_TOKEN).
contentType("application/json").
when().
post("/logout");
response.then().statusCode(200);
System.out.println(response.getBody().asString());
JsonPath jpath = response.jsonPath();
int code = jpath.getInt("code");
System.out.println(code);
assertNotEquals(code, 1000);
}
}
and then i met this
C:\Users\Lenovo\.jdks\openjdk-18.0.1.1\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1.1\lib\idea_rt.jar=50009:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-controls\18\javafx-controls-18.jar;C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-graphics\18\javafx-graphics-18.jar;C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-base\18\javafx-base-18.jar;C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-fxml\18\javafx-fxml-18.jar;C:\Users\Lenovo\.m2\repository\org\apache\groovy\groovy\4.0.1\groovy-4.0.1.jar;C:\Users\Lenovo\.m2\repository\org\apache\groovy\groovy-xml\4.0.1\groovy-xml-4.0.1.jar;C:\Users\Lenovo\.m2\repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;C:\Users\Lenovo\.m2\repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;C:\Users\Lenovo\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\Lenovo\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;C:\Users\Lenovo\.m2\repository\org\apache\httpcomponents\httpmime\4.5.13\httpmime-4.5.13.jar;C:\Users\Lenovo\.m2\repository\org\hamcrest\hamcrest\2.1\hamcrest-2.1.jar;C:\Users\Lenovo\.m2\repository\org\ccil\cowan\tagsoup\tagsoup\1.2.1\tagsoup-1.2.1.jar;C:\Users\Lenovo\.m2\repository\org\apache\groovy\groovy-json\4.0.1\groovy-json-4.0.1.jar;C:\Users\Lenovo\.m2\repository\io\rest-assured\rest-assured-common\5.1.1\rest-assured-common-5.1.1.jar;C:\Users\Lenovo\.m2\repository\io\rest-assured\xml-path\5.1.1\xml-path-5.1.1.jar;C:\Users\Lenovo\.m2\repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;C:\Users\Lenovo\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\Lenovo\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\Lenovo\.m2\repository\com\beust\jcommander\1.82\jcommander-1.82.jar;C:\Users\Lenovo\.m2\repository\org\webjars\jquery\3.6.0\jquery-3.6.0.jar;C:\Users\Lenovo\.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\Lenovo\.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar -p D:\Testing\target\classes;C:\Users\Lenovo\.m2\repository\org\testng\testng\7.6.0\testng-7.6.0.jar;C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-base\18\javafx-base-18-win.jar;C:\Users\Lenovo\.m2\repository\org\apache\commons\commons-lang3\3.11\commons-lang3-3.11.jar;C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-fxml\18\javafx-fxml-18-win.jar;C:\Users\Lenovo\.m2\repository\io\rest-assured\json-path\5.1.1\json-path-5.1.1.jar;C:\Users\Lenovo\.m2\repository\io\rest-assured\rest-assured\5.1.1\rest-assured-5.1.1.jar;C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-graphics\18\javafx-graphics-18-win.jar;C:\Users\Lenovo\.m2\repository\com\googlecode\json-simple\json-simple\1.1.1\json-simple-1.1.1.jar;C:\Users\Lenovo\.m2\repository\org\openjfx\javafx-controls\18\javafx-controls-18-win.jar;C:\Users\Lenovo\.m2\repository\org\controlsfx\controlsfx\11.1.1\controlsfx-11.1.1.jar -m com.vinh.testing/com.vinh.testing.AutomationTesting
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml#18/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857)
at javafx.fxml#18/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724)
at javafx.base#18/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base#18/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base#18/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base#18/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base#18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base#18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base#18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base#18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base#18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base#18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base#18/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base#18/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base#18/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics#18/javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3586)
at javafx.graphics#18/javafx.scene.Scene$MouseHandler.process(Scene.java:3890)
at javafx.graphics#18/javafx.scene.Scene.processMouseEvent(Scene.java:1874)
at javafx.graphics#18/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607)
at javafx.graphics#18/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
at javafx.graphics#18/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#18/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
at javafx.graphics#18/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
at javafx.graphics#18/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
at javafx.graphics#18/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
at javafx.graphics#18/com.sun.glass.ui.View.notifyMouse(View.java:937)
at javafx.graphics#18/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#18/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at javafx.base#18/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml#18/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
at javafx.fxml#18/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1854)
... 29 more
Caused by: org.testng.TestNGException:
An error occurred while instantiating class tests.LoginTest: Unable to make public tests.LoginTest() accessible: module com.vinh.testing does not "exports tests" to module org.testng
at org.testng#7.6.0/org.testng.internal.objects.SimpleObjectDispenser.createInstance(SimpleObjectDispenser.java:99)
at org.testng#7.6.0/org.testng.internal.objects.SimpleObjectDispenser.dispense(SimpleObjectDispenser.java:40)
at org.testng#7.6.0/org.testng.internal.objects.GuiceBasedObjectDispenser.dispense(GuiceBasedObjectDispenser.java:28)
at org.testng#7.6.0/org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:106)
at org.testng#7.6.0/org.testng.internal.ClassImpl.getInstances(ClassImpl.java:136)
at org.testng#7.6.0/org.testng.TestClass.getInstances(TestClass.java:129)
at org.testng#7.6.0/org.testng.TestClass.initTestClassesAndInstances(TestClass.java:109)
at org.testng#7.6.0/org.testng.TestClass.init(TestClass.java:101)
at org.testng#7.6.0/org.testng.TestClass.<init>(TestClass.java:66)
at org.testng#7.6.0/org.testng.TestRunner.initMethods(TestRunner.java:463)
at org.testng#7.6.0/org.testng.TestRunner.init(TestRunner.java:335)
at org.testng#7.6.0/org.testng.TestRunner.init(TestRunner.java:288)
at org.testng#7.6.0/org.testng.TestRunner.<init>(TestRunner.java:178)
at org.testng#7.6.0/org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:639)
at org.testng#7.6.0/org.testng.SuiteRunner.init(SuiteRunner.java:225)
at org.testng#7.6.0/org.testng.SuiteRunner.<init>(SuiteRunner.java:115)
at org.testng#7.6.0/org.testng.TestNG.createSuiteRunner(TestNG.java:1349)
at org.testng#7.6.0/org.testng.TestNG.createSuiteRunners(TestNG.java:1325)
at org.testng#7.6.0/org.testng.TestNG.runSuitesLocally(TestNG.java:1167)
at org.testng#7.6.0/org.testng.TestNG.runSuites(TestNG.java:1099)
at org.testng#7.6.0/org.testng.TestNG.run(TestNG.java:1067)
at com.vinh.testing/com.vinh.testing.CallTest.TestLoginCall.CallTestLogin(TestLoginCall.java:16)
at com.vinh.testing/com.vinh.testing.Controller.Test(Controller.java:63)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 36 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make public tests.LoginTest() accessible: module com.vinh.testing does not "exports tests" to module org.testng
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:191)
at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:184)
at org.testng#7.6.0/org.testng.internal.objects.SimpleObjectDispenser.instantiateUsingDefaultConstructor(SimpleObjectDispenser.java:177)
at org.testng#7.6.0/org.testng.internal.objects.SimpleObjectDispenser.createInstance(SimpleObjectDispenser.java:87)
... 59 more
Im new to TestNG, pls help me.

java.lang.NullPointerException: Location is required still not working

I have also run into some problems trying to get my JavaFX program to run. Like some of the others, I keep getting an error of java.lang.NullPointerException: Location is required. The fxml file is in the Application package. I've tried all the remedies I've found in here, but maybe I'm missing something? Here is my code
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("application/Main.fxml"));
Scene scene = new Scene(root, 400, 400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
And here is the Error
java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:18)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Any help would be much appreciated. Thanks in advance
I lost an entire day battling with this issue in Netbeans. This is how I solved it : Firstly, I put the fxml file in the same package with main (though it can work even in separate packages). Secondly, I used getClassLoader() specifying the path of the file. Here's the code :`
public class Main {
public static void main(String[] args) {
System.out.println("Test = "+Main.class.getClassLoader().getResource("FXMLDocument.fxml"));`
After Running the project, here's the output : ....NetBeansProjects/JavaFXApplicationTest/dist/JavaFXApplicationTest.jar!/FXMLDocument.fxml
Note that Running the file alone was generating an error before.
this will work:
"/application/Main.fxml"
you just need to add a /
Solved the problem by dragging and dropping Main.fxml in src folder.

What is wrong with this FX Application?

I am hours trying to know why this code is wrong, it gives me an Exception, the GUI.fxml is on the root of the project.
public class MyApp extends Application{
#Override
public void start(Stage primaryStage) throws Exception {
String location = "/GUI.fxml";
Parent root = FXMLLoader.load(getClass().getResource(location));
primaryStage.setScene(new Scene(root,300,450));
primaryStage.setTitle("Minha Janela");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Already searched a lot, no solution found yet.
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2825)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771)
at g1.MyApp.start(MyApp.java:13)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
... 1 more
The FXML should not be in the root of the project, but in the classpath. Try relocating the fxml into a source folder.
For general projects, you have a src folder. You can also create your own custom source folder also.
For maven projects, you can try keeping them inside src/main/resources.

JavaFX Hello World throws java.net.ConnectException on start

I seem to be having problems figuring out why the heck I keep getting these java.net.ConnectExceptions. I'm running Windows 7 with a clean install of Java 7u6 x64. I've turned off my firewall (in case that was the issue). I've followed the solutions posted here:
java.net.SocketException: Invalid argument: connect
But nothing is getting rid of these issues. I've even used the Microsoft FixIt application to reset my IP stack. I've also added the "-Djava.net.preferIPv4Stack=true" to the environment variable JAVA_TOOL_OPTIONS variable. Nothing has worked.
This is a JavaFX "Hello World" program from the Netbeans IDE. (On my Mac I have no problems.)
Any help would be GREATLY appreciated! I'm no longer sure where to look to solve this. The end result is that every JavaFX program takes a long time to run. It appears they are all waiting for the timeouts of the socket connections before moving forward with the application. This is not occurring with Java programs, only JavaFX.
Here is the code:
package anotherjavafxtest;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* #author redacted
*/
public class AnotherJavaFXTest extends Application
{
#Override
public void start(Stage primaryStage)
{
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent event)
{
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application. main() serves only as fallback in case the application can not be launched through deployment
* artifacts, e.g., in IDEs with limited FX support. NetBeans ignores main().
*
* #param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
And here is the Exception list:
java.net.ConnectException: Connection refused: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
at sun.net.www.http.HttpClient.New(HttpClient.java:290)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2380)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1546)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.getJSFileFromURL(Unknown Source)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.init(Unknown Source)
at com.sun.deploy.net.proxy.DynamicProxyManager.reset(Unknown Source)
at com.sun.deploy.net.proxy.DeployProxySelector.reset(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.javafx.main.Main.tryToSetProxy(Main.java:572)
at com.javafx.main.Main.launchApp(Main.java:640)
at com.javafx.main.Main.main(Main.java:805)
It's FX vs system proxy issue, FX is trying to check system proxy and failing if it's misconfigured. The reason for that is next enhancement: http://javafx-jira.kenai.com/browse/RT-21705
Add next to JVM arguments in project properties: "-Djavafx.autoproxy.disable=true" or fix system proxy to resolve that.
Shouldn't you be running different app than you supposed, cause that sample code has nothing to do with network connection. Also check the JavaFX Runtime Platform of the Netbeans and hence of your app. You can find it in "Java Platforms" under "Tools" menu.

Resources