A friend and I are working on a simple game, and I have run into a roadblock. The program contains a class, called Area, whose purpose is to read in a series of coordinate pairs into an arraylist that tell the runner class where to place environmental sprites (trees, roads, houses, etc.) in the game screen. At the start of the game, the runner class reads these Area instances into a 2-dimensional array, so you'd have new Area(0,0) , new Area(0,1) ,etc.
The problem I'm having is that, while the Area class functions when the constructor is called from a public static void main within itself, when the runner class tries to create a new Area instance, it throws a FileNotFoundException. Can someone look at this code and help me figure out why it's not working?
public class Area { public static void main(String[]args){ Area area = new Area(0,0); } int x = 0; int y = 0; public ArrayList<int[]>roads = new ArrayList<int[]>(); public ArrayList<int[]>trees = new ArrayList<int[]>(); Scanner input = null; String line = null; String[] locs = null; String search = null; boolean go = true; File file = new File("Areas.txt"); public Area(int xCoord, int yCoord){ x = xCoord; y = yCoord; search = (xCoord + " " + yCoord); try{ input = new Scanner(file); } catch (FileNotFoundException ex) { System.out.println("Cannot open Areas.txt"); System.exit(1); } //all the code past this point is for reading in the coordinate data; it works fine }