import java.io.*;
import java.util.*;
import java.text.*;
public class textFile {
public static void main(String args[]) throws IOException {
Scanner sf = new Scanner(new File("C:\\temp_Name\\DataGym.in.txt"));
int maxIndx = -1;
String text[] = new String[1000];
while (sf.hasNext()) {
maxIndx++;
text[maxIndx] = sf.nextLine();
}
sf.close();
double average[] = new double[100];
for (int j = 0; j <= maxIndx; j++) {
Scanner sc = new Scanner(text[j]);
int k = 0;
while (k <= 10) { //attempt to store all the values of text file (DataGym.in.txt) into the array average[] using Scanner
average[k] = sc.nextDouble();
k++;
}
}
}
}
My code doesn't work and keeps giving me this error at the place where I store sc.nextDouble() into the k element of the array:
java.util.NoSuchElementException:
null (in java.util.Scanner)
System.out.printlnstatements to check thattext[j]actually contains what you think it does? Also, maybe you wantk < 10instead ofk <= 10.averagearray, because you reset the index to 0 for every line