Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling a function from another class - help!

DFanslerDec 7 2014 — edited Dec 10 2014

I realize that this is probably a basic thing for people who have been working with JavaFX for a while, but it is eluding me, and I have been working on it for over a week.

I need to call a function that is in another class.  Here's the deal.  In EntryDisplayController.java, there are 2 possible passwords that can be accepted - one will give full access to the car, the second will limit functions on the car.  So when a password is entered and verified as to which one it is, I need to call a function in MainDisplayController.java to set a variable that will let the system know which password is being used - full or restricted.

So in MainDisplayController.java I have this snippet to see

public class MainDisplayController implements Initializable, ControlledScreen {

    ScreensController myController;

    public static char restrict;

    /**

     * Initializes the controller class.

     */

    @Override

    public void initialize(URL url, ResourceBundle rb) {

        // TODO

    }

    public void setRestriction(){

        restrict = 0;

        restrictLabel.setText("RESTRICTED");

    }

    public void clearRestriction(){

        restrict = 1;

        restrictLabel.setText("");

    }

}

And in EntryScreenDisplay.java I have this snippet:

public class EntryDisplayController implements Initializable, ControlledScreen {

     @FXML

    private Label passwordLabel ;

    static String password = new String();

    static String pwd = new String("");

   

     ScreensController myController;

     private MainDisplayController controller2;

    /**

     * Initializes the controller class.

     */

    @Override

    public void initialize(URL url, ResourceBundle rb) {

        setPW(pwd);    // TODO

    }

   

     @FXML

    private void goToMainDisplay(ActionEvent event){

        if(password.equals ("123456")){

          controller2.clearRestriction();

           myController.setScreen(ScreensFramework.MainDisplayID);

           pwd = "";

           password = "";

           setPW(pwd);

        }

        else if(password.equals ("123457")){

           controller2.setRestriction();

            myController.setScreen(ScreensFramework.MainDisplayID);

           pwd = "";

           password = "";

           setPW(pwd);

           

        }

        else{

            password = "";

            pwd = "";

            setPW(pwd);

        }

    }

}

When I enter the restricted (or full) password, I get a long list of errors, ending with

Caused by: java.lang.NullPointerException

  at velocesdisplay.EntryDisplayController.goToMainDisplay(EntryDisplayController.java:60)

Line 60 is where "controller2.setRestriction(); is.

As always, thanks for any help.

Kind regards,

David

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2015
Added on Dec 7 2014
8 comments
3,313 views