-1

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.

Mageneto
  • 23
  • 2
  • 9
  • You need to show your Scene class code for us, no? You're calling the method on a Scene instance, not on a FXMLDocumentController instance, and actually, I'm not sure why you've posted code for the latter class. Are you confused as to which class actually has the `setPrevStage()` method? – Hovercraft Full Of Eels Nov 12 '14 at 18:36
  • I post the code from both of my Java files so this is all the I have... I guess I am confused with what I am trying to accomplish since this is my first attempt at a GUI. I am attempting to store the current stage/scene so I can close and retrieve it as needed. I'm thinking I need to do some more research to find out how to do what I need to do. – Mageneto Nov 12 '14 at 19:31
  • I've posted all the code now that I have for my project including all my FXMLDocumentController.java file and all my PWManager.java file. There are the only two class files that I have. I'm trying my best to provide you with the information that I have and the error I receive. – Mageneto Nov 12 '14 at 19:43

1 Answers1

1

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);
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • Okay, so I tried replacing my code with root.setPrevStage(stage); and controller.setPrevStage(stage); and neither of these worked. Am I missing something else in my code that needs to be defined first? – Mageneto Nov 12 '14 at 18:55
  • Please explain how its not working. In the meantime, `stage` is not `null` so nothing will be displayed in `setPrevStage`... – Reimeus Nov 12 '14 at 19:13
  • I still receive the same error "Cannot Find Symbol" so I'm not sure if I a missing more code or not... – Mageneto Nov 12 '14 at 19:22
  • @Mageneto: **AGAIN**, please improve your question. – Hovercraft Full Of Eels Nov 12 '14 at 19:25