Getting an array of strings from another class? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Getting an array of strings from another class?

Hi, I am having a problem getting a string of words from another class. I have only included the code not working in the code bit. Getting the words into the class from a file works. But transferring them into the other class doesn't and when I print the words it just returns null. Pls help? public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("Resources/Start.fxml")); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } public class ReadWordsController implements Initializable { String[] word = new String[100]; @Override public void initialize(URL url, ResourceBundle resourceBundle) { StartController startController = new StartController(); word = startController.getWords(); for(int i = 0; i < word.length; i++){ System.out.println(word[i]); } } } public class startController(){ public void subjectButtonClicked ( ActionEvent event) { fileFinder(); Parent parent = FXMLLoader.load(getClass().getResource("/Resources/ReadWords.fxml")); Scene mainScene = new Scene(parent); Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow(); window.setScene(mainScene); window.show(); } public void fileFinder(){ ChooseFile chooseFile = new ChooseFile(); File file = chooseFile.fileChoose(); setWords(chooseFile.getWords(file)); for(int i = 0; i < words.length; i++){ System.out.println("word " + i + getWord(i)); } } public String getWord(int i) { return words[i]; } public String[] getWords(){ return words; } public void setWords(String[] words) { this.

26th May 2020, 3:57 PM
Stephen
1 ответ