InFile Commands not being recognized.
We're doing this assignment in class that has you take a class called Address book, which makes a 500 person array and loads it with information and so on and so forth and sorts through said array. Now...It has a outFile method that works, without throwing errors about the PrintWriter outFile.
I put a method in to set the Data sense there wasn't one using an inFile as the parameter. Now what its doing is its throwing an error even though java.io.* was imported. But its not flagging any of hte outFile with errors, just the InFile, and when I attempted to just create a loop inside the actual program it did the same thing, even with the inFile specified. Any Advice would be appricated.
program
er program for Address book.
import java.io.*;
import java.util.*; //imports of IO and util for file reader, print writer and scanner.
public class AddressBookTest
{
static Scanner Console = new Scanner (System.in); //if user imput is needed
;
public static void main (String [] args) throws FileNotFoundException
{ //start of main
int i=0;
AddressBook Book= new AddressBook(); //array default constructor from Address book.
Scanner inFile = new Scanner (new FileReader("addressbookentries")); //to access the data file
} //end of main.
public static void loadAddressBook (AddressBook addBook) throws FileNotFoundException
{
String first;
String last;
int month;
int day;
int year;
String street;
String city;
String state;
String zip;
String phone;
String pStatus;
while(inFile.hasNext())
{
first.append(inFile.next());
last = inFile.next();
inFile.nextLine();
month = inFile.nextInt();
day = inFile.nextInt();
year = inFile.nextInt();
inFile.nextLine();
street = inFile.nextLine();
city = inFile.nextLine();
state = inFile.nextLine();
zip = inFile.nextLine();
phone = inFile.nextLine();
pStatus = inFile.nextLine();
list[i] = new ExtPerson(first, last, month, day, year, street, city, state, zip, phone, pStatus);
i++;
}
// code to instantiate the input-file object
// Read the data into an ExtPerson object
// Insert the object into the addBook
}
}// end of Class AddressBookTest
The last one is the one where its throwing the errors at the inFile commands, even though I've used them and they've worked in other programs.
This is the error
AddressBook.java:184: cannot find symbol
symbol : method hasNext()
location: class java.io.FileReader
while(inFile.hasNext())
or something similar
Solution: I honestly don't remember exactly what I did. But Part of it was that The method and Main had to both thrown an exception. And then Beyond that I'd missed putting the .txt on the end of hte text file for it to be seen, So it actually ended up being a User Mistake.
But...anyway...if it does it to you, The throw FileNotFoundException goes after both Main and The method. and be sure to have the .txt on the end of the file.