Results 1 to 5 of 5

Thread: Error in Bluej

  1. #1
    deyan8 is offline Member
    Join Date
    Jun 2014
    Posts
    6
    Rep Power
    0

    Default Error in Bluej

    I copied the following program from a java begginer's book:

    import static java.lang.System.out;
    import java.io.File;
    import java.io.IOException;
    import java.util.Scanner;


    class DoPayroll {
    public static void main (String[] args) throws IOException {
    Scanner diskScanner = new Scanner (new File ("Test.txt"));

    for (int empNum = 1; empNum <= 3; empNum++) {
    payOneEmployee (diskScanner);
    }
    }


    static void payOneEmployee (Scanner aScanner) {
    Employee anEmployee = new Employee();
    anEmployee.setName (aScanner.nextLine());
    anEmployee.setJobTitle (aScanner.nextLine());
    anEmployee.cutCheck (aScanner.nextDouble());
    aScanner.nextLine();
    }
    }


    class Employee {
    private String name;
    private String jobTitle;

    public void setName (String nameIn) {
    name = nameIn;
    }


    public String getName() {
    return name;
    }


    public void setJobTitle (String jobTitleIn) {
    jobTitle = jobTitleIn;
    }


    public String getJobTitle() {
    return jobTitle;
    }


    public void cutCheck (double amountPaid) {
    out.printf ("Pay to the order of %s ", name);
    out.printf ("(%s) ***$", jobTitle);
    out.printf ("%,.2f\n", amountPaid);
    }
    }


    Upon running the program the following error is displayed: java.util.NoSuchElementException: No line found (in java.util.Scanner) and it refers to line 20: anEmployee.setJobTitle (aScanner.nextLine()); I honestly do not understand much of what is going on in the code so I wanted to run it to test what happends but then I stumbled on to this problem. I copied it directly from the book (I'm pretty sure because it has now shown up multiple times) even word for word but still nothing. So if anyone can help me with this it would be greatly appreciated :).

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default Re: Error in Bluej

    What is the content of your file Test.txt?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    deyan8 is offline Member
    Join Date
    Jun 2014
    Posts
    6
    Rep Power
    0

    Default Re: Error in Bluej

    It simply says: This is a test.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Error in Bluej

    "Well there's ya problem"

    The code reads one line, reads one line, reads a double. The data in your text file does not match.

  5. #5
    deyan8 is offline Member
    Join Date
    Jun 2014
    Posts
    6
    Rep Power
    0

Similar Threads

  1. BlueJ help! weird error text meesed up
    By linux1man in forum Other IDEs
    Replies: 6
    Last Post: 02-07-2013, 04:54 PM
  2. Urgent Help Needed for some minor Bluej Error
    By IITian in forum Other IDEs
    Replies: 5
    Last Post: 02-07-2013, 04:19 PM
  3. BlueJ with Modified Error Subsystem
    By java software in forum Java Software
    Replies: 0
    Last Post: 12-19-2011, 11:49 AM
  4. Error Compiling Project in BlueJ
    By java1337 in forum New To Java
    Replies: 9
    Last Post: 06-17-2011, 09:04 PM
  5. BlueJ 2.2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-07-2007, 03:28 PM

Tags for this Thread

Posting Permissions

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