Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
  1. #21
    asmodean is offline Member
    Join Date
    Jul 2010
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Does the array have a variable name?

    What does "zeros to the rest" mean?

    Do some more debugging by adding some println()s to see why the values are zeros.
    Print out each line as you read it in.
    Print out each time a new Student object is created.
    Print out the value of index as each Student object is added to the array.
    Quote Originally Posted by Norm View Post
    What does the print out of the value of index show?


    You need to work on one part of the program at a time.
    First concentrate on filling the array with data.
    After you think its full, use the Arrays.toString() method to print out the contents of the array.
    If there are any holes/null values or the values are all the same go back over your code that fills the array and find the problem.


    here's the output:


    index=0
    student[index]=StudentDemo$Student@5122cdb6
    getFirstName()=Bob
    index=0
    student[index]=StudentDemo$Student@43ef9157
    getFirstName()=john
    index=0
    student[index]=StudentDemo$Student@252f0999
    getFirstName()=paul
    index=0
    student[index]=StudentDemo$Student@331f2ee1
    getFirstName()=mark
    index=0
    student[index]=StudentDemo$Student@443ecfff
    getFirstName()=jane
    index=0
    student[index]=StudentDemo$Student@77c99159
    getFirstName()=megan
    index=0
    student[index]=StudentDemo$Student@5265a77f
    getFirstName()=lanie
    index=0
    student[index]=StudentDemo$Student@fd7ad1c
    getFirstName()=robert
    index=0
    student[index]=StudentDemo$Student@18a61164
    getFirstName()=jimmy
    index=0
    student[index]=StudentDemo$Student@3ebfc8e0
    getFirstName()=joan


    So the loop is not advancing thru the elements of the array?

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    So the loop is not advancing thru the elements of the array
    It looks like the value of index is not being changed! Go back to where you think you are changing it and see what the problem is. The nested while looks fishy. Print the values of line and index in the for loop outside of the while loop.
    Also don't forget to add the print of Arrays.toString(student) to show the whole array.

    StudentDemo$Student@5265a77f
    This output is from the default toString() method. Not very useful.
    Go back to my post about adding a toString() method to the Student class

  3. #23
    asmodean is offline Member
    Join Date
    Jul 2010
    Posts
    18
    Rep Power
    0

    Default

    I put the line:

    String line = inputFile.nextLine();

    inside the first loop and got rid of the:

    line = inputFile.hasNext()

    and got rid of the while(inputFile.hasNext())

    and it works now.

    Thanks for all the help, Norm. I appreciate it.

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

Page 2 of 2 FirstFirst 12

Similar Threads

  1. deleting an element from an array
    By moamen in forum New To Java
    Replies: 11
    Last Post: 01-03-2010, 05:38 PM
  2. [SOLVED] indexing an element in an array help!
    By anthonym2121 in forum New To Java
    Replies: 1
    Last Post: 04-03-2009, 06:21 PM
  3. Replies: 1
    Last Post: 03-31-2009, 06:40 AM
  4. Unique element in an array
    By revathi17 in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 08:44 AM
  5. Max element in an Array
    By mew in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 05:26 PM

Posting Permissions

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