Cannot find symbol error when calling method from different class file

1.7k views Asked by At

I'm trying to call a method form a separate class file to my main program java file but when I try to call the method on an object, I get the error symbol cannot be found for the method. Both files are in the same directory.

//This is my main java file for the program
package pwmanager;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


/**
 *
 * @author 176878
 */
public class PWManager extends Application {

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("Login.fxml"));

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("Password Manager");
    stage.setPrevStage();  //Error occurs here.
    stage.show();

}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);

}

}

//This is the other .java file where the method is declared.
        /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pwmanager;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.EventType;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javax.xml.crypto.Data;


/**
 *
 * @author 176878
 */
public class FXMLDocumentController implements Initializable {

@FXML
private Button loginButton;
private Button addAcct;
private Button removeAcct;

@FXML
public Stage prevStage;
public Stage currentStage;




@FXML
public void loginButtonAction(ActionEvent event) throws IOException {
   System.out.println("You clicked me, logging in!");


    Stage stage = new Stage();


    FXMLLoader loader = new FXMLLoader(getClass().getResource("MainScreen.fxml"));

    Parent mainScreen = (Parent)loader.load();
    Scene scene = new Scene(mainScreen);

    stage.setScene(scene);
    stage.setTitle("Password Manager");
    //prevStage.close();
    stage.show();
}    
@FXML
public void addAcctAction(ActionEvent event) throws IOException {
   System.out.println("You clicked me, adding account!");

}  

 @FXML
public void removeAcctAction(ActionEvent event) throws IOException {
   System.out.println("You clicked me, removing account!");
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
}    

}

I need to store the current stage so I can call it back or close the stage out.

1

There are 1 answers

4
Reimeus On

setPrevStage is defined in FXMLDocumentController not Stage. You need to inject the former into the main PWManager class so that it can be invoked

controller.setPrevStage(stage);