sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.29k stars 1.06k forks source link

getText get null #282

Closed sinadarvi closed 7 years ago

sinadarvi commented 7 years ago

hi, i do this :

JFXTextField text = new JFXTextField();
text.setText("hello");

and after that i do this

if(text.getText()!=null ) {
                text.getText();
            }

and i get NullPointerException on text.getText() !!!

i think it's cause of textIsNull , but i don't sure!! thanks.

jfoenixadmin commented 7 years ago

Hello, if you can provide the whole code, we might be able to help. otherwise will close this issue, as the provided info is not enough.

Regards,

sinadarvi commented 7 years ago

hi, okey, here is my code :

        JFXTextField ipGrabber = new JFXTextField();
        JFXTextField portGrabber = new JFXTextField();
        ipGrabber.setPromptText("IP :");
        ipGrabber.setText("192.168.26.1");
        portGrabber.setPromptText("Port :");
        portGrabber.setText("26881");

        JFXButton connect = new JFXButton("Connect");
        connect.setOnAction(event -> {

            if(ipGrabber.getText()!=null && portGrabber.getText()!=null) {
                mclient.serverIP = ipGrabber.getText();
                mclient.serverPort = Integer.parseInt(portGrabber.getText());
            }

and here is erorr:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at controllers.MowerStatusController.lambda$initializeConnectingLayout$1(MowerStatusController.java:147) //code : mclient.serverIP = ipGrabber.getText();
thetric commented 7 years ago

Are you certain that mclient isn't null?

sinadarvi commented 7 years ago

@thetric no.thanks. mclient was null. problem fixed. sorry for interrupting...