· 8 years ago · Feb 08, 2018, 11:46 AM
1Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
2at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
3at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
4at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
5at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
6at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
7at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
8at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
9at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
10at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
11at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
13at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
14at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
15at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
16at javafx.event.Event.fireEvent(Event.java:198)
17at javafx.scene.Node.fireEvent(Node.java:8413)
18at javafx.scene.control.Button.fire(Button.java:185)
19at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
20at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
21at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
22at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
23at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
24at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
25at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
26at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
27at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
28at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
29at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
30at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
31at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
32at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
33at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
34at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
35at javafx.event.Event.fireEvent(Event.java:198)
36at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
37at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
38at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
39at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
40at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
41at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
42at java.security.AccessController.doPrivileged(Native Method)
43at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
44at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
45at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
46at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
47at com.sun.glass.ui.View.notifyMouse(View.java:937)
48at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
49at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
50at java.lang.Thread.run(Thread.java:748)
51Caused by: java.lang.reflect.InvocationTargetException
52at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
53at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
54at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
55at java.lang.reflect.Method.invoke(Method.java:498)
56at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
57at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
58at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
59at java.lang.reflect.Method.invoke(Method.java:498)
60at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
61at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
62... 48 more
63Caused by: java.lang.NullPointerException
64at Login.loginController.login(loginController.java:37)
65... 58 more
66
67if (database.isLogin(username.getText(), password.getText())){
68
69String createManagement = "CREATE TABLE IF NOT EXISTS Management (name varchar(255), surname varchar(255), username varchar(255), password varchar(255))";
70
71public boolean insertManagement(String name, String surname, String username, String password) {
72 try {
73 PreparedStatement preparedStatement = connection.prepareStatement("insert into Management values (?,?,?,?);");
74 preparedStatement.setString(1, name);
75 preparedStatement.setString(2, surname);
76 preparedStatement.setString(3, username);
77 preparedStatement.setString(4, password);
78 preparedStatement.execute();
79 } catch (SQLException e) {
80 System.out.println("Error with insert Management to the table");
81 e.printStackTrace();
82 return false;
83 }
84 return true;
85}
86
87
88public boolean isLogin(String username, String password) throws SQLException {
89 PreparedStatement preparedStatement = null;
90 ResultSet resultSet = null;
91 String query = "SELECT * FROM Management where username = ?, password = ?";
92 try {
93 preparedStatement = connection.prepareStatement(query);
94 preparedStatement.setString(1, username);
95 preparedStatement.setString(2, password);
96
97 resultSet = preparedStatement.executeQuery();
98 if (resultSet.next()) {
99 return true;
100 }else {
101 return false;
102 }
103 } catch (Exception e) {
104 return false;
105 }
106
107public Management(String name, String surname, String username, String password){
108 this.name = new SimpleStringProperty(name);
109 this.surname = new SimpleStringProperty(surname);
110 this.username = new SimpleStringProperty(username);
111 this.password = new SimpleStringProperty(password);
112}
113
114public StringProperty name;
115public StringProperty nameProperty(){return name;}
116public void setName(String value){nameProperty().set(value);}
117public String getName(){return nameProperty().get();}
118
119
120public StringProperty surname;
121public StringProperty surnameProperty(){return surname;}
122public void setSurname(String value){surnameProperty().set(value);}
123public String getSurname(){return surnameProperty().get();}
124
125public StringProperty username;
126public StringProperty usernameProperty(){return username;}
127public void setUsername(String value){usernameProperty().set(value);}
128public String getUsername(){return usernameProperty().get();}
129
130public StringProperty password;
131public StringProperty passwordProperty(){return password;}
132public void setPassword(String value){passwordProperty().set(value);}
133public String getPassword(){return passwordProperty().get();}
134}
135
136public void login (ActionEvent actionEvent){
137 try {
138 if (database.isLogin(username.getText(), password.getText())){
139 isConnected.setText("Connected");
140 }else {
141 System.out.println("Wrong username or password!");
142 }
143 }catch (SQLException e){
144 System.out.println("Wrong username or password!");
145 e.printStackTrace();
146 }
147}