So, I keep getting a java.util.InputMismatchException null(in java.util.Scanner). I have used the same logic in a different program with a list of integers. This program takes from a list of numbers from 1-2000. I've made sure that "integers.txt" is an actual text file in the project. I am using BlueJ to code this. Can anyone shed some light on this?
import java.util.Scanner; import java.io.*; public class Sorting { private static int[] a = new int[2000]; private int v; private Scanner fileScan, dataScan; private static String oneLine; public Sorting() throws IOException { int place = 0; fileScan = new Scanner(new File("integers.txt")); while(fileScan.hasNext()) { oneLine = fileScan.nextLine(); dataScan = new Scanner(oneLine); v = dataScan.nextInt(); //it errors here a[place] = v; place++; } } public static void main(String args[]) throws IOException { Sorting s = new Sorting(); BubbleSort bubble = new BubbleSort(); InsertionSort insert = new InsertionSort(); SelectionSort select = new SelectionSort(); bubble.sort(a); insert.sort(a); select.sort(a); System.out.println("Bubble Sort had " + bubble.getCompare() + " comparisons and " + bubble.getExchange() + " exchanges."); System.out.println("Insertion Sort had " + insert.getCompare() +" comparisons and " + insert.getExchange() + " exchanges."); System.out.println("Selection Sort had " + select.getCompare() +" comparisons and " + select.getExchange() + " exchanges."); } }