public Game() throws FileNotFoundException {
map = new ArrayList<Room>();
String room1Desc;
int room1Name = 1;
String line1 = null;
try(BufferedReader br = new BufferedReader(new FileReader("Roomprompts.txt"))) {
for(int i = 1;i<room1Name;i++){
br.readLine();
line1 = br.readLine();
System.out.println(line1);
}
} catch (IOException e) {
System.out.println("There was an error");
}
// Room( name, description, N, S, W, E )
map.add(new Room(line1, "A dank room that smells of troll", Direction.NOEXIT, 2, Direction.NOEXIT, 1));
map.add(new Room("Forest", "A leafy woodland", Direction.NOEXIT, Direction.NOEXIT, 0, Direction.NOEXIT));
map.add(new Room("Cave", "A dismal cave with walls covered in luminous moss", 0, Direction.NOEXIT, Direction.NOEXIT, 3));
map.add(new Room("Dungeon", "A nasty, dark cell", Direction.NOEXIT, Direction.NOEXIT, 2, Direction.NOEXIT));
player = new Actor("player", "a loveable game-player", map.get(0));
}
I'm trying to read a line 1 from a text file I have on my desktop called "Roomprompts.txt". I have tried to make the line to read into a string, but the output I always get is "There was an error". I'm not sure why it's not reading the first line from the text file into the room name. The point of this is to have the console print "This is a stinky trolls room", but it just gives back the message "There was an error".
Thank you @Scott Hunter. I never even knew that existed, it says the file was not found, but I'm looking at it right now. I fixed the file not found error, and now it says that it is null, but at the same time it tells me it has to be initialized as null?