- #1
ProPatto16
- 326
- 0
Hello,
Am writing java, using netbeans,
For what should be a simple try.. catch with a while loop, I am getting the error.
i have an excel file with the strings i want to display. the file is all fine, checked to make sure no empty cells etc etc.
When i get to the second last element, the error occurs. there's some 35 elements in the file so the loop is working, its just ending prematurely. i know this is usually because the method call occurs more than necessary i.e. in the loop twice moves it forward too much etc, but in my piece of code I am struggling to find where this is happening.
the following code is the try..catch method that does all the method calling.
just not sure why the iteration is ahead of where it should be. it iterates through 7 cycles then the error is thrown right in between the last call for getName and then the last phone and email arent displayed. its rather strange actually, the 'name' cells in the excel doc are first and last names in each cell, and it only shows the first name of the last person, then throws the error for the rest.
any help would be great :)
Am writing java, using netbeans,
For what should be a simple try.. catch with a while loop, I am getting the error.
i have an excel file with the strings i want to display. the file is all fine, checked to make sure no empty cells etc etc.
When i get to the second last element, the error occurs. there's some 35 elements in the file so the loop is working, its just ending prematurely. i know this is usually because the method call occurs more than necessary i.e. in the loop twice moves it forward too much etc, but in my piece of code I am struggling to find where this is happening.
the following code is the try..catch method that does all the method calling.
Code:
public void readCSVFile()
{
StudentList list = new StudentList();
System.out.printf( "%-15s%-15s%-15s%15s\n", "StudentID", "Student Name",
"Phone", "Email" );
try
{
while ( input.hasNext() )
{
list.setId( input.next() );
list.setName( input.next() );
list.setPhone( input.next() );
list.setEmail( input.next() );
System.out.printf( "%-15s%-15s%-15s%15s\n",
list.getId(), list.getName(),
list.getPhone(), list.getEmail() );
} // end while
} // end try
catch ( NoSuchElementException elementException )
{
System.err.println( "File improperly formed." );
input.close();
System.exit( 1 );
} // end catch
just not sure why the iteration is ahead of where it should be. it iterates through 7 cycles then the error is thrown right in between the last call for getName and then the last phone and email arent displayed. its rather strange actually, the 'name' cells in the excel doc are first and last names in each cell, and it only shows the first name of the last person, then throws the error for the rest.
any help would be great :)