In my latest project i use a .txt file called "atestfile.txt" which resides inside my projects /raw folder, which i created:
and this is its content:
now using these few simple lines of code..
i want my application to insert the words from the textfile into my ArrayList line by line as seen in this questions awesome first answer.
However, no Toast will appear, and even worse, i will receive an IndexOutOfBoundsException for the test.get(3); line i use and the application crashes.
I tried all day to get rid of this error but have not succeeded yet in doing so. So since there are a lot of smart people around here and i'd love to learn something about this problem, i thought i'd ask you guys for help first before throwing my computer out of the window.
I'll provide you guys with my error message, copy & pasteable code aswell as my packet structure for some more help on this issue.
package com.niklas.cp.citypopulation;
final ArrayList<String> test = new ArrayList<String>();
try {
Scanner scanner = new Scanner(new File("android.resource:// com.niklas.cp.citypopulation/raw/atestfile.txt"));
while(scanner.hasNextLine()){
makeToast(scanner.nextLine(),1);
test.add(scanner.nextLine());
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String abc = test.get(3);
tv_highscore.setText(abc);