Hi there. I'm trying to do a file reader which is accessible via a menu system but i keep getting the error “unhandled exception type FileNotFoundException” at theelse inputCommandFile();import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JOptionPane; import edu.cmu.ri.createlab.terk.robot.finch.Finch; public class RobotController1 { private static Finch myf = null; public static void main(String[] args) { myf = new Finch(); String lastCommand = null; int count =1; for (String input = getInput(); !input.equals("End Program"); input = getInput()) { if (!input.equals(lastCommand)) { if (input.equals("Forward")) moveForward(); else if (input.equals("Back")) moveBack(); else if (input.equals("Left Turn")) moveLeft(); else if (input.equals("Right Turn")) moveRight(); else if (input.equals("Nose Colour")) greenLED(); else if (input.equals("Three Point Turn")) threePointTurn(); //Three point turn else inputCommandFile(); lastCommand = input; System.out.println(count); } else { JOptionPane.showMessageDialog(null, input + " cannot be chosen directly after " + lastCommand,"ERROR",0); } } while (count <8); System.out.println("Finch Disconnected..."); myf.quit(); } private static String getInput() { Object[] possibilities = {"Forward","Back","Left Turn","Right Turn", "Nose Colour" ,"Three Point Turn","Input Command File","End Program"}; String c = (String)JOptionPane.showInputDialog(null,"Robot Controller \n\nChoose a command:\n\n","Robot Controller",JOptionPane.PLAIN_MESSAGE, null,possibilities,"Forward"); if (c == null || c.length() == 0) c = "End Program"; return c; } private static String inputCommandFile(String s) throws FileNotFoundException { File file = new File("h:\\My Documents\\Inputfile.txt"); Scanner sc = new Scanner(new FileInputStream(file)); int numoflinesread=0; int Maxlines=7;//maximum amount of commands it can read is 7 String line = null; while(sc.hasNextLine()) { line = sc.nextLine(); if (line.indexOf("Nose") > -1) { stringconversion(line); } else if (line.indexOf("Forward ") > -1) { stringconversion(line); } else if (line.indexOf("Backward") > -1) { stringconversion(line); } else if (line.indexOf("Left") > -1) { stringconversion(line); } else if (line.indexOf("Right") > -1) { stringconversion(line); } numoflinesread++; if (numoflinesread==Maxlines) { break; } return line; } return line; }
Please help me, I've watched tutorials etc. but I'm at my wits end now. Thank you