You might have a line where there isn't an ampersand (&).
Now, it is always a nice practice to assure yourself that what you're going to access exists, so you won't end up with NullPointers or IndexOutOfBounds.
List<SoruKelime> questions = new ArrayList<>();
try {
Scanner myReader = new Scanner(myFile);
while (myReader.hasNextLine()) {
String data;
data = myReader.nextLine();
int index = data.indexOf('&');
if(index==-1 || index > data.length){
//There is no &, do something
}else{
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;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…