-1
 clueless about this error..i am trying to set the text property of a label when i click on a button..it keeps giving this error  :




 Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1770)
        at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1653)
        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:8390)
        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:3758)
        at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486)
        at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
        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$350(GlassViewEventHandler.java:385)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$136/128942111.get(Unknown Source)
        at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
        at com.sun.glass.ui.View.notifyMouse(View.java:927)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
        at com.sun.glass.ui.win.WinApplication$$Lambda$38/636526176.run(Unknown Source)
        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:1765)
        ... 50 more
    Caused by: java.lang.NullPointerException
        at classes.LoginController.output(LoginController.java:26)
        ... 60 more

this is the controller:

public class LoginController  {

    @FXML private Label labelOne;


    public void output(ActionEvent actionEvent) {
        labelOne.setText("HEY");
    }
}

this is the fxml code for the controls:

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/8" 
      xmlns:fx="http://javafx.com/fxml/1" fx:controller="classes.LoginController">
   <children>
      <Label layoutX="43.0" layoutY="117.0" prefHeight="17.0" prefWidth="66.0" text="Username" />
      <TextField id="textField" layoutX="141.0" layoutY="113.0" prefHeight="25.0" prefWidth="169.0" />
      <Label layoutX="43.0" layoutY="165.0" prefHeight="17.0" prefWidth="66.0" text="Password" />
      <PasswordField id="passwordField" layoutX="141.0" layoutY="161.0" prefHeight="25.0" prefWidth="169.0" />
      <Label alignment="CENTER" contentDisplay="CENTER" layoutX="87.0" layoutY="33.0" prefHeight="47.0" prefWidth="180.0" text="LOGIN">
         <font>
            <Font size="31.0" />
         </font>
      </Label>
      <Button id="loginButton" layoutX="244.0" layoutY="211.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="66.0" text="Login" />
      <Button id="signupButton" layoutX="43.0" layoutY="211.0" mnemonicParsing="false" text="SignUp" onAction="#output" />
      <Label id="labelOne" layoutX="141.0" layoutY="79.0" prefHeight="30.0" prefWidth="125.0" >
         <font>
            <Font size="20.0" />
         </font>
      </Label>
   </children>
</Pane>

i am certain this is a fairly basic problem but i'm stuck and clueless on this problem..also what is the best method i could use to connect a javafx application to a database...and what database would be the best option to embed within this application.....

caleb grimah
  • 183
  • 1
  • 15
  • 2
    It is not returning null. It is throwing a `NullPointerException`. Quite a difference. – user207421 Jun 27 '16 at 01:23
  • @EJP there is no where mentioned in that Nul pointer Link you have provided the cause of this null pointer .. if a person is new and provided id ...and causing null how would he find out ? i voted up his question because i didnt know either that withoud fx: can cause null pointer exception i tried it then gave him answer – Arif Nouman Khan Jun 27 '16 at 09:50

1 Answers1

1

use H2 database which is best embedded and also on localhost and the second issue

add fx: to your ids

like

<Label fx:id="labelOne" layoutX="141.0" layoutY="79.0" prefHeight="30.0" prefWidth="125.0" >
         <font>
            <Font size="20.0" />
         </font>
      </Label>
Arif Nouman Khan
  • 367
  • 1
  • 12