public List<SoruKelime> getAllQuestion() {
List<SoruKelime> questions = new ArrayList<>();
try {
Scanner myReader = new Scanner(myFile);
while (myReader.hasNextLine()) {
String data;
data = myReader.nextLine();
int index = data.indexOf("&");
String question = data.substring(0, index);
String answer = data.substring(index+1);
SoruKelime soru = new SoruKelime();
soru.setSoru(question);
soru.setKelime(answer);
questions.add(soru);
}
myReader.close();
} catch (FileNotFoundException exception) {
exception.printStackTrace();
}
return questions;
}
@Override
public void initialize(URL url, ResourceBundle rb) {
FileProcess fileProcess = new FileProcess();
List<SoruKelime> sorular = new LinkedList<SoruKelime>();
SoruKelime cekilenSoru = new SoruKelime();
sorular = (ArrayList<SoruKelime>) fileProcess.getAllQuestion();
cekilenSoru = sorular.get(0);
this.soruLabel.setText(cekilenSoru.getSoru());
}
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1967)
at word_game.FileProcess.getAllQuestion(FileProcess.java:53)
at word_game.GameController.initialize(GameController.java:34)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
while i'm reading a file in java with javafx i'm having this kind of issue. i've tried to change linkedList to List but that didn't work. I don't know what else I can do. Can you help me about that