0

I am not sure why I am getting this error. Can anyone help?

public static void main(String[] args) throws IOException, InvalidMidiDataException {

MusicEditorCreater.Builder builder = new MusicEditorCreater.Builder();

IMusicEditorModel model = MusicReader.parseFile(new FileReader(args[0]), builder);
IMusicEditorView view;
switch (args[1]) {
  case "text": view = new SheetMusicTextView();
    break;
  case "gui": view = new SheetMusicView();
    break;
  case "midi": view = new MidiView();
    break;
  case "combined": view = new MidiGuiView();
    break;
  default:
    throw new IllegalArgumentException("Not a valid view");
}

I'm creating a Music Editor for class and this is the very last part, I just don't understand why it's throwing this error. Thanks.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
mmv456
  • 39
  • 1
  • 8
  • 2
    You seem to be calling this without passing in any args on the command line. – Hovercraft Full Of Eels Jun 16 '17 at 13:25
  • 1
    Some other similar questions may be found in [this Google search](https://www.google.com/#q=site:stackoverflow.com+java+arrayindexoutofboundsexception+args+main). – Hovercraft Full Of Eels Jun 16 '17 at 13:27
  • Other than that you can put `switch (args[1]) {...` and this `IMusicEditorModel model = MusicReader.parseFile(new FileReader(args[0]), builder);` inside try-catch. Also you can do this inside `catch(Exception e){e.printStackTrace();}` This will tell you exactly what is going wrong in your code – Kangkan Jun 16 '17 at 13:30

0 Answers0