title: IndexOutofBounds exception creating a maze
body: <p>I'm working on a school assignment where I am supposed to create a maze from a textfile. My problem is creating the maze. I know it's probably an easy fix, but I am really stuck and need to get this done.. Any suggestions? </p>
  
  <pre><code>package application;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.Scanner;
  import javafx.application.Application;
  import javafx.stage.FileChooser;
  import javafx.stage.FileChooser.ExtensionFilter;
  import javafx.stage.Stage;
  import javafx.scene.Scene;
  import javafx.scene.layout.GridPane;
  
  public class Main extends Application {
  LabyrintRute[][] Labyrint;
  int X;
  int Y;
  int startx;
  int starty;
  Spiller spilleren;
  int sizeX;
  int sizeY;
  
  @Override
  public void start(Stage primaryStage) {
      try {
          GridPane root = new GridPane();
          Spiller spilleren = new Spiller(startx, starty);
          filLeser();
  
          root.add(spilleren.getUtseende(), spilleren.getxPossisjon(), spilleren.getyPossisjon());
  
          for(int x = 0; x&lt;X; x++){
              for(int y = 0; y&lt;Y; y++){
          root.add(Labyrint[x][y].getUtseende(), x, y);
          }
          }
  
          Scene scene = new Scene(root, X*10, Y*10);
          scene.setOnKeyPressed(new FilLytter(this));
          scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
          primaryStage.setScene(scene);
          primaryStage.show();
      } catch(Exception e) {
          e.printStackTrace();
      }
  }
  
  public void filLeser() {
      String teksten = "";
      File fila;
  
      int rad = 0;
  
      FileChooser filvelger = new FileChooser();
      filvelger.setTitle("Åpne en tekstfil");
      filvelger.getExtensionFilters().add(new ExtensionFilter("Text Files", "*.txt"));
      fila = filvelger.showOpenDialog(null);
  
  
      try (Scanner filleser = new Scanner(fila)) {
          X = filleser.nextInt();
          Y = filleser.nextInt();
          teksten = filleser.nextLine();
  
          Labyrint = new LabyrintRute [X][Y];
          while (filleser.hasNext()) {
              teksten = filleser.nextLine();
              for (int i = 0;i&lt; X;i++) {
                  char tegn = teksten.charAt(i);
                  switch (tegn) {
                  case '#':
                      Labyrint[i][rad] = new Vegg(i, rad);
                      break;
                  case ' ':
                      Labyrint[i][rad] = new Gang(i, rad);
                      break;
                  case '-':
                      Labyrint[i][rad] = new Utgang(i, rad);
                      break;
                  case '*':
                      Labyrint[i][rad] = new Gang(i, rad);
                      startx = i;
                      starty = rad;
                      break;
                  }
                      rad++;
  
                  }
              }
          } catch (FileNotFoundException e) {
              System.out.println("Kan ikke åpne fila!");
              e.printStackTrace();
          }
      }
  
  public void flyttSpiller(int deltax, int deltay) {
      int nyx = spilleren.getxPossisjon() + deltax;
      int nyy = spilleren.getyPossisjon() + deltay;
      Labyrint[nyx][nyy].flyttHit(spilleren);
  
  }
  
  public static void main(String[] args) {
      launch(args);
  }
  }
  </code></pre>
  
  <p>The "Vegg"(wall) class:</p>
  
  <pre><code>package application;
  
  import javafx.scene.Node;
  import javafx.scene.paint.Color;
  import javafx.scene.shape.Rectangle;
  
  public class Vegg extends LabyrintRute {
  private Node utseende;
  
  public Vegg(int xKoordinat, int yKoordinat) {
      super(xKoordinat, yKoordinat);
      utseende = new Rectangle(10, 10, Color.MEDIUMPURPLE);
  }
  
  @Override
  public void flyttHit(Spiller spilleren) {
      //spilleren.setxPossisjon(getxKoordinat());
      //spilleren.setyPossisjon(getyKoordinat());
  }
  
  @Override
  public Node getUtseende() {
      return utseende;
  }
  
  }
  </code></pre>
  
  <p>Abstract class:</p>
  
  <pre><code>package application;
  
  import javafx.scene.Node;
  
  public abstract class LabyrintRute {
  private int xKoordinat;
  private int yKoordinat;
  
  public LabyrintRute(int xKoordinat, int yKoordinat) {
      this.xKoordinat = xKoordinat;
      this.yKoordinat = yKoordinat;
  }
  
  public int getxKoordinat() {
      return xKoordinat;
  }
  
  public int getyKoordinat() {
      return yKoordinat;
  }
  
  public abstract void flyttHit(Spiller spilleren);
  
  public abstract Node getUtseende();
  
  }
  </code></pre>
  
  <p>I also have a "Gang" (passage), and a "Utgang" (exit) class. They are similiar to the "Vegg" class.</p>
  
  <p>Would really appreciate inputs! Sorry for the norwegian code.. </p>