I'm having trouble with the code at this part. I get a successfull build but when I press my login button I get no home screen. thw error thats presented in the stack trace is this:
ant -f /home/tacomeat/NetBeansProjects/BlackJackFx jfxsa-run
init:
Deleting: /home/tacomeat/NetBeansProjects/BlackJackFx/build/built-jar.properties
deps-jar:
Updating property file:/home/tacomeat/NetBeansProjects/BlackJackFx/build/built-jar.properties
Copying 1 file to /home/tacomeat/NetBeansProjects/BlackJackFx/build/classes
compile:
Deleting directory/home/tacomeat/NetBeansProjects/BlackJackFx/dist/lib
Copying 1 file to /home/tacomeat/NetBeansProjects/BlackJackFx/dist/lib
Detected JavaFX Ant API version 1.3
Launching <fx:jar> task from /usr/lib/jvm/java-8-oracle/jre/../lib/ant-javafx.jar
Warning: From JDK7u25 the Codebase manifest attribute should be used to restrict JAR repurposing.
Please set manifest.custom.codebase property to override the current default non-secure value '*'.
Launching <fx:deploy> task from /usr/lib/jvm/java-8- oracle/jre/../lib/ant-javafx.jar
No base JDK. Package will use system JRE.
No base JDK. Package will use system JRE.
jfx-deployment-script:
jfx-deployment:
jar:
Copying 13 files to /home/tacomeat/NetBeansProjects/BlackJackFx/dist/run831901790
jfx-project-run:
Executing /home/tacomeat/NetBeansProjects/BlackJackFx/dist/run831901790/BlackJackFx. jar using platform /usr/lib/jvm/java-8-oracle/jre/bin/java
Login Now
Exception in thread "JavaFX Application Thread"java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:745)
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:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 48 more
Caused by: java.lang.NullPointerException
at com.blackjack.view.LoginController.isValidCredentials(LoginController.java:76)
at com.blackjack.view.LoginController.handleButtonAction(LoginController.java:58)
... 58 more
Deleting directory /home/tacomeat/NetBeansProjects/BlackJackFx/dist/run831901790
jfxsa-run:
BUILD SUCCESSFUL (total time: 10 seconds)
And here is my code after a few modifications
public class LoginController implements Initializable {
@FXML
private Label welcome;
@FXML
private Label warningLbl;
@FXML
private TextField username_box;
@FXML
private TextField password_box;
@FXML
private void handleButtonAction(ActionEvent event) throws IOException {
System.out.println("Login Now");
Parent home_page_parent = FXMLLoader.load(getClass().getResource("table.fxml"));
Scene home_page_scene = new Scene(home_page_parent);
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
if (isValidCredentials())
{
app_stage.hide();
app_stage.setScene(home_page_scene);
app_stage.show();
}
else
{
username_box.clear();
password_box.clear();
warningLbl.setText("Invalid Username or Password! ");
}
}
private boolean isValidCredentials()
{
boolean let_in = false;System.out.println("SELECT * FROM Users WHERE USERNAME= " + "'" + username_box.getText() + "'"
+ "AND PASSWORD=" + "'" + password_box.getText() + "'");
Connection c = null;
java.sql.Statement stmt = null;
try{
c = DriverManager.getConnection("jdbc:sqlite:BjFx.db");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM Users WHERE USERNAME= " + "'" + username_box.getText() + "'"
+ " AND PASSWORD= " + "'" + password_box.getText() + "'");
while ( rs.next() ) {
if (rs.getString("USERNAME") != null && rs.getString("PASSWORD") != null) {
String username = rs.getString("USERNAME");
System.out.println( "USERNAME = " + username );
String password = rs.getString("PASSWORD");
System.out.println("PASSWORD = " + password);
let_in = true;
}
}
rs.close();
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Operation done successfully");
return let_in;
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
where is my error cause I just don't see it?
Aucun commentaire:
Enregistrer un commentaire