Results 1 to 5 of 5
  1. #1
    Tenn is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default 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.
    Last edited by Tenn; 02-13-2009 at 04:49 PM.

  2. #2
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    I don't know the solution to your problem(actually I figured it out further down post), but I can help you get it:
    1. Use <CODE> code here </CODE> (replace < and > with [ and ])tags to put your code in, keeps tabs the same, makes it a lot more easy to read.
    2. Only post the section that gives the error, helpful to put error line in bold/red.
    Now for your problem: When you get errors, you should research what they mean. Cannot find symbol. First check: Is the symbol(method/class/field/etc) visible? (did I import it? is is public?) you answered that yourself. Next step, Check out the API. Google "java api 6". Very helpful. I just did it for you, I went to the FileReader class in the api, and There is no "hasNext()" method. It actually only inherits methods from superclasses, has none of its own, but hasNext() is not among the inherited methods. There is no next() method either. I think that you were thinking of a different class, not FileReader.. Scanner class has those methods, maybe use it instead? Hope this helped.
    Last edited by MK12; 02-13-2009 at 03:41 AM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  3. #3
    Tenn is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    I figured it out last night. Sorry I didn't update the post. And I'll remember both suggestions. Thanks ^^;

  4. #4
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Could you please post the solution? (in code tags and only the part that caused problem) for people who have the same problem, if they search google and find this thread then they will be able to see the solution. And go tot Thread Tools at the top of the page and pick Mark As Solved so everyone knows that the thread is solved.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  5. #5
    Tenn is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    I posted what I recalled. I was dorking around iwth it attempting to get it to work last night so I honestly don't remember the exacts.

Similar Threads

  1. Replies: 28
    Last Post: 10-26-2010, 05:39 AM
  2. Replies: 13
    Last Post: 09-17-2009, 08:56 AM
  3. javac command not recognized
    By sunshine39 in forum New To Java
    Replies: 7
    Last Post: 03-04-2009, 04:54 AM
  4. 'javac' is not recognized as an internal or external command
    By sam_1032002@btopenworld.c in forum New To Java
    Replies: 3
    Last Post: 10-18-2008, 03:40 AM
  5. Replies: 6
    Last Post: 07-30-2008, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •