I am having trouble reading the first word of a text file. If the first word equals 'Circle' I want to create a new Circle object in my array.
FileInputStream fileIn = new FileInputStream("shapeFile.txt");
Scanner scan = new Scanner(fileIn);
while(scan.hasNextLine()) {
String shape = scan.next();
if(shape.equals("Circle")) {
myShapes.addShape(new Circle(scan.nextInt(), scan.nextInt(), scan.nextInt(), Color.RED));
}
}
I am getting the following error for the above code, pointing to the line String shape = scan.next();
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1371)
at shapes.ShapeManagement.main(ShapeManagement.java:151)
Java Result: 1
If anyone could help me resolve this I would be most grateful.