Without mapping fxml this code run perfectly and load fxml
if i map fxml getting exception
i try alot but unable to understand what is the problem.....
SpringFxmlLoader class method load() return statement not returning anything because of which i think exception occur
javafx.fxml.LoadException:/E:/aa/JavaFXwithSpringBoot/bin/test/spring/boot/LoginPage.fxml:15
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579) at
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at
javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at
test.spring.boot.config.SpringFXMLLoader.load(SpringFXMLLoader.java:34)
at
test.spring.boot.config.StageManager.loadViewNodeHierarchy(StageManager.java:80)
at
test.spring.boot.config.StageManager.switchScene(StageManager.java:31)
at test.spring.boot.Main.displayInitialScene(Main.java:35) at
test.spring.boot.Main.start(Main.java:24) 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)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at
com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source) Caused by:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type 'test.spring.boot.LoginPageController'
available at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1090)
at
javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:929)
at
javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at
javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at
javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707) at
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527) ... 16 more
Exception in Application start method 2017-10-24 17:18:03.779 ERROR
6416 --- [lication Thread] test.spring.boot.config.StageManager :
Unable to load FXML view >> /test/spring/boot/LoginPage.fxml
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type 'test.spring.boot.LoginPageController'
available at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1090)
~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:929)
~[jfxrt.jar:na] at
javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
~[jfxrt.jar:na] at
javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
~[jfxrt.jar:na] at
javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
~[jfxrt.jar:na] at
javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
~[jfxrt.jar:na] at
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527) ~[jfxrt.jar:na]
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
~[jfxrt.jar:na] at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
~[jfxrt.jar:na] at
test.spring.boot.config.SpringFXMLLoader.load(SpringFXMLLoader.java:34)
~[bin/:na] at
test.spring.boot.config.StageManager.loadViewNodeHierarchy(StageManager.java:80)
[bin/:na] at
test.spring.boot.config.StageManager.switchScene(StageManager.java:31)
[bin/:na] at test.spring.boot.Main.displayInitialScene(Main.java:35)
[bin/:na] at test.spring.boot.Main.start(Main.java:24) [bin/:na] at
com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
[jfxrt.jar:na] at
com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
~[jfxrt.jar:na] at
com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
~[jfxrt.jar:na] at java.security.AccessController.doPrivileged(Native
Method) ~[na:1.8.0_131] at
com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
~[jfxrt.jar:na] at
com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
~[jfxrt.jar:na] at com.sun.glass.ui.win.WinApplication._runLoop(Native
Method) ~[jfxrt.jar:na] at
com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
~[jfxrt.jar:na] at java.lang.Thread.run(Unknown Source)
~[na:1.8.0_131]
2017-10-24 17:18:03.846 INFO 6416 --- [lication Thread]
s.c.a.AnnotationConfigApplicationContext : Closing
org.springframework.context.annotation.AnnotationConfigApplicationContext#f096164:
startup date [Tue Oct 24 17:18:02 IST 2017]; root of context hierarchy
2017-10-24 17:18:03.848 INFO 6416 --- [lication Thread]
o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed
beans on shutdown java.lang.reflect.InvocationTargetException at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at
com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
sun.launcher.LauncherHelper$FXHelper.main(Unknown Source) Caused by:
java.lang.RuntimeException: Exception in Application start method at
com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at
com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source) Caused by:
java.lang.NullPointerException: Root cannot be null at
javafx.scene.Scene.(Scene.java:336) at
javafx.scene.Scene.(Scene.java:194) at
test.spring.boot.config.StageManager.prepareScene(StageManager.java:62)
at test.spring.boot.config.StageManager.show(StageManager.java:36) at
test.spring.boot.config.StageManager.switchScene(StageManager.java:32)
at test.spring.boot.Main.displayInitialScene(Main.java:35) at
test.spring.boot.Main.start(Main.java:24) 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)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at
com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more Exception running application test.spring.boot.Main
Main.java
#ComponentScan("test.spring.boot")
#SpringBootApplication
public class Main extends Application {
protected ConfigurableApplicationContext springContext;
protected StageManager stageManager;
#Override
public void start(Stage primaryStage) throws IOException {
stageManager = springContext.getBean(StageManager.class, primaryStage);
displayInitialScene();
}
#Override
public void init() throws Exception
{
springContext=springBootApplicationContext();
}
protected void displayInitialScene() {
stageManager.switchScene(FxmlView.LOGIN);
}
#Override
public void stop() throws Exception {
springContext.close();
}
private ConfigurableApplicationContext springBootApplicationContext() {
SpringApplicationBuilder builder = new SpringApplicationBuilder(Main.class);
String[] args = getParameters().getRaw().stream().toArray(String[]::new);
return builder.run(args);
}
public static void main(String[] args) {
Application.launch(args);
}
}
Controller.java
public class LoginPageController implements Initializable{
#FXML
private TextField txtUserName;
#FXML
private PasswordField txtPassward;
#FXML
private Button btnLogin;
#FXML
private Label lblLogin;
#Autowired
private UserService userService;
#Lazy
#Autowired
private StageManager stageManager;
#FXML
public void login()
{
if(userService.authenticate(txtUserName.getText(), txtPassward.getText()))
{
stageManager.switchScene(FxmlView.USER);
}
else
{
lblLogin.setText("Login Failed.");
}
}
#Override
public void initialize(URL location, ResourceBundle resources) {
}
}
FxmlView.java
public enum FxmlView {
USER {
#Override
public String getTitle() {
return getStringFromResourceBundle("user.title");
}
#Override
public String getFxmlFile() {
return "/test/spring/boot/TestSpring.fxml";
}
},
LOGIN {
#Override
public String getTitle() {
return getStringFromResourceBundle("login.title");
}
#Override
public String getFxmlFile() {
return "/test/spring/boot/LoginPage.fxml";
}
};
public abstract String getTitle();
public abstract String getFxmlFile();
String getStringFromResourceBundle(String key){
return ResourceBundle.getBundle("Bundle").getString(key);
}
}
SpringFxmlLoader.java
#Component
public class SpringFXMLLoader {
private final ResourceBundle resourceBundle;
private final ApplicationContext context;
#Autowired
public SpringFXMLLoader(ApplicationContext context, ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
this.context = context;
}
public Parent load(String fxmlPath) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setControllerFactory(context::getBean); //Spring now FXML Controller Factory
loader.setResources(resourceBundle);
loader.setLocation(getClass().getResource(fxmlPath));
System.out.println("springfxmlloader class : "+fxmlPath);
System.out.println("LOADER : ");
return loader.load();
}
}
StageManager.java
public class StageManager {
private static final Logger LOG = getLogger(StageManager.class);
private final Stage primaryStage;
private final SpringFXMLLoader springFXMLLoader;
public StageManager(SpringFXMLLoader springFXMLLoader, Stage stage) {
System.out.println(">>>>>>>>>>>>>>>>>> 1");
this.springFXMLLoader = springFXMLLoader;
this.primaryStage = stage;
}
public void switchScene(final FxmlView view) {
System.out.println(">>>>>>>>>>>>>>>>>> 2");
Parent viewRootNodeHierarchy = loadViewNodeHierarchy(view.getFxmlFile());
show(viewRootNodeHierarchy, view.getTitle());
}
private void show(final Parent rootnode, String title) {
Scene scene = prepareScene(rootnode);
//scene.getStylesheets().add("/styles/Styles.css");
//primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setTitle(title);
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.centerOnScreen();
System.out.println(">>>>>>>>>>>>>>>>>> 3");
try {
primaryStage.show();
} catch (Exception exception) {
logAndExit ("Unable to show scene for title" + title, exception);
}
}
private Scene prepareScene(Parent rootnode){
System.out.println(">>>>>>>>>>>>>>>>>> 4");
Scene scene = primaryStage.getScene();
System.out.println("SCN >>>>>>>>>>>>>>>>>>>> : "+ scene);
if (scene == null) {
scene = new Scene(rootnode);
}
scene.setRoot(rootnode);
return scene;
}
private Parent loadViewNodeHierarchy(String fxmlFilePath) {
System.out.println(">>>>>>>>>>>>>>>>>> 5 path: "+fxmlFilePath);
Parent rootNode = null;
try {
System.out.println(fxmlFilePath);
rootNode = springFXMLLoader.load(fxmlFilePath);
System.out.println(">>>>5 : try");
Objects.requireNonNull(rootNode, "A Root FXML node must not be null");
} catch (Exception exception) {
System.out.println("File path????? : "+fxmlFilePath);
logAndExit("Unable to load FXML view >> " + fxmlFilePath, exception);
exception.printStackTrace();
}
return rootNode;
}
private void logAndExit(String errorMsg, Exception exception) {
System.out.println(">>>>>>>>>>>>>>>>>> 6");
LOG.error(errorMsg, exception, exception.getCause());
Platform.exit();
}
}
You forgot to add a Stereotype on your LoginPageController class that's why Spring is telling you:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'test.spring.boot.LoginPageController'
As the class is not marked the component-scan will ignore it and there will be no bean register assignable for that type.
Try:
#Controller
public class LoginPageController implements Initializable{
#Autowired
public LoginPageController(UserService userService, private StageManager stageManager){
this.userService = userService;
this.stageManager = stageManager;
}
}
Related
I am a beginner of JavaFX. When I create a JavaFX project with Scene Builder. I just run and check the default user interface and got an error. The full stack trace is attached below. I don't know how to solve this problem.
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: 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 javafxapplication9.JavaFXApplication9.start(JavaFXApplication9.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
... 1 more
Exception running application javafxapplication9.JavaFXApplication9
C:\Users\kobinath\Documents\NetBeansProjects\JavaFXApplication9\nbproject\build-impl.xml:1052: The following error occurred while executing this line:
C:\Users\kobinath\Documents\NetBeansProjects\JavaFXApplication9\nbproject\build-impl.xml:806: Java returned: 1
BUILD FAILED (total time: 1 second)
i don't know why. what i tried so far i attached below
public class JavaFXApplication9 extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
FXMLDocumentController
public class FXMLDocumentController implements Initializable {
#FXML
private Label label;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
I have created a javaFx application with a RESTful service , I am trying to show the retrieved data to the javaFx application but I keep getting an error.
Alarm.java
public class Alarm implements Externalizable {
private final LongProperty id = new SimpleLongProperty();
private final LongProperty floorNum = new SimpleLongProperty();
private final LongProperty roomNum = new SimpleLongProperty();
private final LongProperty smokeLevel = new SimpleLongProperty();
private final LongProperty co2level = new SimpleLongProperty();
public Alarm() {
}
public long getId() {
return id.get();
}
public LongProperty idProperty() {
return id;
}
public void setId(long id) {
this.id.set(id);
}
public long getFloorNum() {
return floorNum.get();
}
public LongProperty floorNumProperty() {
return floorNum;
}
public void setFloorNum(long floorNum) {
this.floorNum.set(floorNum);
}
public long getRoomNum() {
return roomNum.get();
}
public LongProperty roomNumProperty() {
return roomNum;
}
public void setRoomNum(long roomNum) {
this.roomNum.set(roomNum);
}
public long getSmokeLevel() {
return smokeLevel.get();
}
public LongProperty smokeLevelProperty() {
return smokeLevel;
}
public void setSmokeLevel(long smokeLevel) {
this.smokeLevel.set(smokeLevel);
}
public long getCo2level() {
return co2level.get();
}
public LongProperty co2levelProperty() {
return co2level;
}
public void setCo2level(long co2level) {
this.co2level.set(co2level);
}
#Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeLong(getId());
out.writeLong(getFloorNum());
out.writeLong(getRoomNum());
out.writeLong(getSmokeLevel());
out.writeLong(getCo2level());
}
#Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
setId(in.readLong());
setFloorNum(in.readLong());
setRoomNum(in.readLong());
setSmokeLevel(in.readLong());
setCo2level(in.readLong());
}
}
The method I use to retrieve the JSON data
public List<Alarm> getAlarms() throws RemoteException {
ArrayList <Alarm> alarms = null;
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
//HTTP GET method
HttpGet httpget = new HttpGet("http://localhost:8080/alarms");
System.out.println("Executing request " + httpget.getRequestLine());
// Create a custom response handler
ResponseHandler < String > responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
};
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println("----------------------------------------");
System.out.println(responseBody);
//Gson gson = new Gson();
Type alarmListType = new TypeToken<ArrayList<Alarm>>(){}.getType();
alarms = new Gson().fromJson(responseBody,alarmListType);
} catch (IOException e) {
e.printStackTrace();
}
return alarms;
}
The error code I get
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Failed to invoke public javafx.beans.property.LongProperty() with no args
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:113)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:212)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson(Gson.java:932)
at com.google.gson.Gson.fromJson(Gson.java:897)
at com.google.gson.Gson.fromJson(Gson.java:846)
at rmiServer.serviceImpl.AlarmServiceImpl.getAlarms(AlarmServiceImpl.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:283)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:260)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy0.getAlarms(Unknown Source)
at rmiClient.alarmForm.AlarmForm.setMain(AlarmForm.java:65)
at rmiClient.client.Main.start(Main.java:30)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:110)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:212)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson(Gson.java:932)
at com.google.gson.Gson.fromJson(Gson.java:897)
at com.google.gson.Gson.fromJson(Gson.java:846)
at rmiServer.serviceImpl.AlarmServiceImpl.getAlarms(AlarmServiceImpl.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
... 1 more
Exception running application rmiClient.client.Main
I have created the javaFX application through an RMI server and client hence the file names, but according to my knowledge those files does not impact this error.
I have two theories as to why this might not work.
Maybe gson cannot set Properties. Try using a long instead of a LongProperty.
As far as I know the fields in your Java code have to have the exact same name as the fields in the json you are trying to parse. Make sure that the names match.
I'm trying to add a horizontal line to a linechart in JavaFX. Found this post in SO and now trying to modify it to work in my case, however I'm getting an error, and hopefully someone can see what is the problem here.
Here is the controller code:
package gems.view;
public class GUImainController implements Initializable, Observer
{
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
private ArrayList<Float> tempArr = new ArrayList<>();
private ArrayList<String> tempTimeArray = new ArrayList<>();
private Series<String, Number> tempChart = new Series<>();
#FXML
private LineChartWithMarker<String, Number> lcTemperature = new LineChartWithMarker<>(xAxis,yAxis);
#Override
public void initialize(URL arg0, ResourceBundle arg1)
{
yAxis.setPrefWidth(35);
xAxis.setLabel("Temperature \\u00b0");
yAxis.setLabel("Time");
tempChart = new XYChart.Series<String, Number>();
lcTemperature.getData().add(tempChart);
tempArr.add(observable.getLatestMeasurementsFromServer().getTemperature());
tempTimeArray.add(observable.getLatestMeasurementsFromServer().getDateTime().getTime());
for (int i = 0; i < tempArr.size(); i++)
{
tempChart.getData().add(new XYChart.Data<>(tempTimeArray.get(i), tempArr.get(i)));
}
tempChart.getNode().lookup(".chart-series-line").setStyle("-fx-stroke: orange;");
String s = "test";
Data<String, Number> verticalMarker = new Data<>(s, 20);
lcTemperature.addHorizontalValueMarker(verticalMarker);
}
Here is the LineChartWithMarker class:
package gems.view;
import java.util.Objects;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.shape.Line;
public class LineChartWithMarker<X,Y> extends LineChart
{
private ObservableList<Data<X, Y>> horizontalMarkers;
public LineChartWithMarker(CategoryAxis xAxis, NumberAxis yAxis)
{
super(xAxis, yAxis);
horizontalMarkers = FXCollections.observableArrayList(data -> new Observable[] {data.YValueProperty()});
horizontalMarkers.addListener((InvalidationListener)observable -> layoutPlotChildren());
}
public void addHorizontalValueMarker(Data<X, Y> marker)
{
Objects.requireNonNull(marker, "the marker must not be null");
if (horizontalMarkers.contains(marker)) return;
Line line = new Line();
marker.setNode(line );
getPlotChildren().add(line);
horizontalMarkers.add(marker);
}
public void removeHorizontalValueMarker(Data<X, Y> marker) {
Objects.requireNonNull(marker, "the marker must not be null");
if (marker.getNode() != null) {
getPlotChildren().remove(marker.getNode());
marker.setNode(null);
}
horizontalMarkers.remove(marker);
}
#Override
protected void layoutPlotChildren() {
super.layoutPlotChildren();
for (Data<X, Y> horizontalMarker : horizontalMarkers) {
Line line = (Line) horizontalMarker.getNode();
line.setStartX(0);
line.setEndX(getBoundsInLocal().getWidth());
line.setStartY(getYAxis().getDisplayPosition(horizontalMarker.getYValue()) + 0.5); // 0.5 for crispness
line.setEndY(line.getStartY());
line.toFront();
}
}
}
And here is the FXML (just the part for line chart):
<LineChart fx:id="lcTemperature" minWidth="100.0" prefHeight="155.0" prefWidth="708.0" BorderPane.alignment="CENTER">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis autoRanging="false" lowerBound="20.0" minorTickCount="10" minorTickLength="10.0" side="LEFT" tickLabelGap="10.0" tickLength="20.0" tickUnit="1.0" upperBound="30.0" />
</yAxis>
</LineChart>
Herew is the error stack:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
/C:/My%20Projects/GEMS_SEP2/GEMS_SEP2/bin/FXML/GUIgems.fxml:42
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at gems.view.GUIuserClient.start(GUIuserClient.java:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Caused by: java.lang.IllegalArgumentException: Can not set gems.view.LineChartWithMarker field gems.view.GUImainController.lcTemperature to javafx.scene.chart.LineChart
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)
at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:765)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
... 12 more
Exception running application gems.view.GUIuserClient
By the way, GUIgems.fxml:42 is the last line of the FXML code I have posted above.
Also, its maybe worth mentioning that the line chart works fine if I am using a simple LineChart, like this:
#FXML
private LineChart<String, Number> lcTemperature;
It does not work when I write like this:
#FXML
private LineChartWithMarker<String, Number> lcTemperature = new LineChartWithMarker<>(xAxis,yAxis);
Alright so I managed to find a solution, if anyone will find themselves in the same situation.
Constructor of LineChartWithMarker needs to look like this:
public LineChartWithMarker(#NamedArg("xAxis") Axis<X> xAxis,
#NamedArg("yAxis") Axis<Y> yAxis)
{
super(xAxis, yAxis);
horizontalMarkers = FXCollections.observableArrayList(data -> new Observable[] {data.YValueProperty()});
horizontalMarkers.addListener((InvalidationListener)observable -> layoutPlotChildren());
}
And the FXML needs to look like this:
<?import gems.view.LineChartWithMarker?>
<LineChartWithMarker fx:id="lcTemperature" minWidth="100.0" prefHeight="155.0" prefWidth="708.0" BorderPane.alignment="CENTER">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis autoRanging="false" lowerBound="20.0" minorTickCount="10" minorTickLength="10.0" side="LEFT" tickLabelGap="10.0" tickLength="20.0" tickUnit="1.0" upperBound="30.0" />
</yAxis>
</LineChartWithMarker>
As the title says, i have a server application which defines a RmiServiceExporter like this:
#Bean
RmiServiceExporter exporter() {
Class<Service> serviceInterface = Service.class;
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceInterface(serviceInterface);
exporter.setService(service());
exporter.setServiceName("Service");//serviceInterface.getSimpleName());
exporter.setRegistryPort(1099);
return exporter;
}
and a client application, in which i have a spring configured loginScene and the RmiProxyFactoryBean.
This is the Client Spring configuration:
#Configuration
public class ClientConfig {
#Bean
public Stage primaryStage() {
return new Stage();
}
#Bean
RmiProxyFactoryBean service() {
RmiProxyFactoryBean rmiProxyFactory = new RmiProxyFactoryBean();
rmiProxyFactory.setServiceUrl("rmi://127.0.0.1:1099/Service");
rmiProxyFactory.setServiceInterface(Service.class);
return rmiProxyFactory;
}
#Bean
public Scene loginScene(){
final FXMLLoader loader = new FXMLLoader(getClass().getResource("/FXMLs/LoginFXML.fxml"));
try {
return new Scene(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
In the LoginController, i have an initialization method, which tries to get the service bean from the ApplicationContext, but instead NoSuchBeanDefinitionException is thrown.
Here is the LoginController:
#Data
public class LoginController {
private ApplicationContext factory;
private Service service;
#FXML private TextField textfield_username;
#FXML private PasswordField textfield_password;
#FXML
public void initialize(){
factory = new AnnotationConfigApplicationContext("Configurations.ClientConfig");
service = (Service) factory.getBean("service");
}
#FXML
private void textUsernameKeypressed(KeyEvent keyEvent) {
onEnterLogin(keyEvent);
}
#FXML
private void textPasswordKeypressed(KeyEvent keyEvent) {
onEnterLogin(keyEvent);
}
#FXML
private void buttonKeypressed(KeyEvent keyEvent) {
onEnterLogin(keyEvent);
}
private void onEnterLogin(KeyEvent keyEvent){
if (keyEvent.getCode().equals(KeyCode.ENTER))
login();
}
#FXML
private void loginButtonPressed(ActionEvent actionEvent) {
login();
}
private void login(){
try {
service.login(textfield_username.getText(), textfield_password.getText());
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setContentText("Login succesfull");
alert.show();
} catch (ServiceException e) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setContentText("Login failed: " + e.getMessage());
alert.show();
}
}
}
And here is the exception stacktrace:
/usr/lib/jvm/java-8-openjdk/bin/java -javaagent:/opt/intellij-idea-ultimate-edition/lib/idea_rt.jar=38303:/opt/intellij-idea-ultimate-edition/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-openjdk/jre/lib/charsets.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/jce.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/jsse.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/resources.jar:/usr/lib/jvm/java-8-openjdk/jre/lib/rt.jar:/home/bobby/Faculta/CurseAutobuze/Client/out/production/classes:/home/bobby/Faculta/CurseAutobuze/Client/out/production/resources:/home/bobby/Faculta/CurseAutobuze/Common/out/production/classes:/home/bobby/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.16.18/557d13dcb647038dc687390711ccb5c9b3ffbd60/lombok-1.16.18.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework.data/spring-data-jpa/2.0.5.RELEASE/51b2e315174e32b4c8a4841a147002555add076c/spring-data-jpa-2.0.5.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-core/5.2.13.Final/830492a74b3013ef75135ea4120b2ac23fa7ad9f/hibernate-core-5.2.13.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-validator/6.0.7.Final/9e923bb3f45e7e4c7555677f0aab7953d4ea1251/hibernate-validator-6.0.7.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.postgresql/postgresql/42.2.1/b7f61848ac43ae9fa6e38935bfd75628b7fc9086/postgresql-42.2.1.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework.data/spring-data-commons/2.0.5.RELEASE/f5357c650f63f3a187d3d4086a9e9132f33851a6/spring-data-commons-2.0.5.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/5.0.4.RELEASE/dc83e08ecdb4ab28339f87358b53d75b4a8d1b9/spring-orm-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/5.0.4.RELEASE/3e76d08c851113077642c5704f0f94d5ce58e905/spring-context-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aop/5.0.4.RELEASE/f8e029e54c0267dadb6b9f713f3feb54ec4f3a0e/spring-aop-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/5.0.4.RELEASE/6b5ac0db11d81d6319ebd0bb253b2f01713df3ab/spring-jdbc-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.0.4.RELEASE/7afc193c5d2b812ee6d2ccaf6fcc81fb83bfb4a7/spring-tx-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.0.4.RELEASE/7a8c3d48d4c33621e64d1399721d8e067450fcbd/spring-beans-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-expression/5.0.4.RELEASE/4bda161f2e34c1486f2527a23eb47293567f473c/spring-expression-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.0.4.RELEASE/2221a957b5561a34f044350ba4e30ef5870254a3/spring-core-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.aspectj/aspectjrt/1.8.12/afaa5bdae313ed3ea119eb26c8848fca21e8b04e/aspectjrt-1.8.12.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.25/da76ca59f6a57ee3102f8f9bd9cee742973efa8a/slf4j-api-1.7.25.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.hibernate.common/hibernate-commons-annotations/5.0.1.Final/71e1cff3fcb20d3b3af4f3363c3ddb24d33c6879/hibernate-commons-annotations-5.0.1.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.hibernate.validator/hibernate-validator/6.0.7.Final/8b9d9c7ec8c73963ea0fe81912fc67711a4ef76/hibernate-validator-6.0.7.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.jboss.logging/jboss-logging/3.3.1.Final/c46217ab74b532568c0ed31dc599db3048bd1b67/jboss-logging-3.3.1.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.hibernate.javax.persistence/hibernate-jpa-2.1-api/1.0.0.Final/5e731d961297e5a07290bfaf3db1fbc8bbbf405a/hibernate-jpa-2.1-api-1.0.0.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.22.0-GA/3e83394258ae2089be7219b971ec21a8288528ad/javassist-3.22.0-GA.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/antlr/antlr/2.7.7/83cd2cd674a217ade95a4bb83a8a14f351f48bd0/antlr-2.7.7.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.jboss.spec.javax.transaction/jboss-transaction-api_1.2_spec/1.0.1.Final/4441f144a2a1f46ed48fcc6b476a4b6295e6d524/jboss-transaction-api_1.2_spec-1.0.1.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.jboss/jandex/2.0.3.Final/bfc4d6257dbff7a33a357f0de116be6ff951d849/jandex-2.0.3.Final.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/com.fasterxml/classmate/1.3.1/2ad2fd09dcf5607ca96f8ef432096a96986c40a/classmate-1.3.1.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/dom4j/dom4j/1.6.1/5d3ccc056b6f056dbf0dddfdf43894b9065a8f94/dom4j-1.6.1.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.0.4.RELEASE/3053e2bad0a18571bdbb9596ce51f9d458f5934f/spring-jcl-5.0.4.RELEASE.jar:/home/bobby/.gradle/caches/modules-2/files-2.1/javax.validation/validation-api/2.0.1.Final/cb855558e6271b1b32e716d24cb85c7f583ce09e/validation-api-2.0.1.Final.jar Main
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.
javafx.fxml.LoadException:
/home/bobby/Faculta/CurseAutobuze/Client/out/production/resources/FXMLs/LoginFXML.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2571)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at Configurations.ClientConfig.loginScene(ClientConfig.java:32)
at Configurations.ClientConfig$$EnhancerBySpringCGLIB$$5da32339.CGLIB$loginScene$2(<generated>)
at Configurations.ClientConfig$$EnhancerBySpringCGLIB$$5da32339$$FastClassBySpringCGLIB$$e0e4f3e3.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
at Configurations.ClientConfig$$EnhancerBySpringCGLIB$$5da32339.loginScene(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:88)
at Main.start(Main.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2566)
... 36 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'service' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:686)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1205)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085)
at Controllers.LoginController.initialize(LoginController.java:28)
... 46 more
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: org.springframework.beans.factory.support.NullBean cannot be cast to javafx.scene.Scene
at Main.start(Main.java:19)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
... 1 more
Exception running application Main
Process finished with exit code 1
I solved the problem here was the problem:
#FXML
public void initialize(){
factory = new AnnotationConfigApplicationContext("Configurations.ClientConfig");
service = (Service) factory.getBean("service");
}
it should've been:
#FXML
public void initialize(){
factory = new AnnotationConfigApplicationContext(ClientConfig.class);
service = (Service) factory.getBean("service");
}
This error is produced by launching the jar file in cmd with "G:\Orchid\OrchidFX.jar". When launching the application through IntelliJ everything runs just fine. Also, in File->ProjectStructure we have added sqljdbc4.jar to the library.
The Error:
javafx.fxml.LoadException:
file:/G:/Orchid/OrchidFX.jar!/DatabaseSettingsForm.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at fxproject.ApplicationSplashScreen.loadDatabaseScreen(ApplicationSplashScreen.java:35)
at fxproject.ApplicationSplashScreen.start(ApplicationSplashScreen.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
... 19 more
Caused by: java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDataSource
at fxproject.OrchidDataSource.setDataSourceSettings(OrchidDataSource.java:56)
at fxproject.OrchidDataSource.<init>(OrchidDataSource.java:50)
at DataSettingsController.initialize(DataSettingsController.java:34)
... 28 more
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDataSource
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 31 more
OrchidDataSource.java:
package fxproject;
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;
public class OrchidDataSource
{
private final String driverType = "jdbc";
private final String dbmsType = "sqlserver";
private String hostname = "192.168.1.173";
private int portNumber = 1433;
private String databaseName = "OrchidDB";
private final String propertyValue = "user=Blah;password=blahblah";
private String username = "blah"; //andrew
private String password = "password";
public String getHostname()
{
return hostname;
}
public int getPortNumber()
{
return portNumber;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
public String getDatabaseName()
{
return databaseName;
}
private SQLServerDataSource dataSource;
private static OrchidDataSource orchidDataSource;
public OrchidDataSource()
{
setDataSourceSettings();
setCurrentDataSource(this);
}
private void setDataSourceSettings()
{
dataSource = new SQLServerDataSource();
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setServerName(hostname);
dataSource.setPortNumber(portNumber);
dataSource.setDatabaseName(databaseName);
}
public void setDataSourceSettings(String username, String password, String hostname, int portNumber, String databaseName)
{
this.username = username;
this.password = password;
this.hostname = hostname;
this.portNumber = portNumber;
this.databaseName = databaseName;
setDataSourceSettings();
}
public void setCurrentDataSource(OrchidDataSource orchidDataSource)
{
this.orchidDataSource = orchidDataSource;
}
public static OrchidDataSource getCurrentDataSource()
{
return orchidDataSource;
}
public Connection getConnection() throws SQLException
{
return dataSource.getConnection();
}
}
DataSettingsController:
package fxproject;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.sql.Connection;
public class DataSettingsController
{
public static final String VIEWCONTROLLER_TITLE= "DataSettings";
#FXML
TextField fieldhostname;
#FXML
TextField fieldportnumber;
#FXML
TextField fielddatabasename;
#FXML
TextField fieldusername;
#FXML
PasswordField fieldpassword;
public DataSettingsController()
{
}
#FXML
public void initialize()
{
OrchidDataSource dataSource = new OrchidDataSource();
fieldhostname.setText(dataSource.getHostname());
fieldportnumber.setText(String.valueOf(dataSource.getPortNumber()));
fielddatabasename.setText(dataSource.getDatabaseName());
fieldusername.setText(dataSource.getUsername());
fieldpassword.setText(dataSource.getPassword());
}
#FXML
protected void handleButtonSubmit(ActionEvent e)
{
try
{
OrchidDataSource dataSource = new OrchidDataSource();
dataSource.setDataSourceSettings(fieldusername.getText(),
fieldpassword.getText(),
fieldhostname.getText(),
Integer.parseInt(fieldportnumber.getText()),
fielddatabasename.getText());
Connection connection = OrchidDataSource.getCurrentDataSource().getConnection();
connection.prepareStatement("{call SelectClientStatus()}").executeQuery(); ///low data query to test connection
new MainSystem();
Node source = (Node) e.getSource();
Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
catch(Exception ae)
{
new OrchidAlertBox("Error", "Database cannot be reached.");
}
}
}