What does this error mean?
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1347)
at phonebook.main(phonebook.java:69)
Press any key to continue . . .
And these are the chunks of code I am using:
Code:
import java.util.Scanner;
import java.io.*;
public class phonebook
{
public static void main (String[] args) throws IOException
{
String first, last, address, city, state, zipcode, number, hold;
int zipint;
Scanner filer, disector;
pages entries = new pages ();
filer = new Scanner (new File("phonebook.txt"));
while (filer.hasNext())
{
hold = filer.nextLine();
disector = new Scanner (hold);
disector.useDelimiter("\n");
while (disector.hasNext())
{
first = disector.next();
last = disector.next();
address = disector.next();
city = disector.next();
state = disector.next();
zipcode = disector.next();
number = disector.next();
zipint = Integer.parseInt(zipcode);
entries.addEntry (last, first, address, city, state, number, zipint);
}
}
System.out.println (entries);
}}
Code:
public class bookentry
{
private String First, Last, Address, City, State, Num;
private int Zipint;
public bookentry (String first, String last, String address, String city, String state, String num, int zip)
{
First = first;
Last = last;
Address = address;
City = city;
State = state;
Num = num;
Zipint = zip;
}
}
Code:
public class pages
{
private bookentry[] bookpages;
private int count;
public pages ()
{
bookpages = new bookentry[25];
count = 0;
}
public void addEntry (String first, String last, String address, String city, String state, String num, int zip)
{
if (count == bookpages.length)
increaseSize();
bookpages[count] = new bookentry (first, last, address, city, state, num, zip);
count++;
}
private void increaseSize ()
{
bookentry[] temp = new bookentry[bookpages.length * 2];
for (int potato = 0; potato < bookpages.length; potato++)
temp[potato] = bookpages[potato];
bookpages = temp;
}
public String toString ()
{
String endgame = "";
for (int counter = 0; counter < count; counter++)
{
endgame += bookpages[counter].toString() + "\n";
}
return endgame;
}
}
and the text file composed of randomized data
Quote:
Cecil \n Harding \n 1453 Short Street \n Adams \n Oregon \n 97810 \n (541)987-2556
Myra \n Gray \n 1815 Coleman \n Avenue \n Adair Village \n Oregon \n 97330 \n ( 541)995-9849
Trina \n Lewis \n 1834 Byers \n Lane \n Adrian \n Oregon \n 97901 \n (541)948-6587
Damion \n Carver \n 194 Frum Street \n Albany \n Oregon \n 97321 \n (541)344-4814
Darren \n Weiss \n 4627 Sherwood Circle \n Amity \n Oregon \n 97101 \n (503)956-9501
Cristina \n Fuller \n 4835 Boone Street \n Antelope \n Oregon \n 97001 \n (541)489-8468
Dale \n George \n 2739 Findley Avenue \n Arlington \n Oregon \n 97812 \n (541)894-0959
Ann \n Oliver \n 2585 Ben Street \n Ashland \n Oregon \n 97520 \n (541)845-0661
Clinton \n Eaton \n 3217 College View \n Astoria \n Oregon \n 97520 \n (503)369-5198
Jennifer \n Webster \n 1211 Heavner Court \n Athena \n Oregon \n 97813 \n (541)864-9463
Graham \n Albert \n 4908 Finwood Road \n Aumsville \n Oregon \n 97325 \n (503)378-6187
Hunter \n Burgess \n 1460 High Meadow Lane \n Aurora \n Oregon \n 97002 \n (503)338-0919
Raquel \n Durham \n 4743 Masonic Drive \n Baker City \n Oregon \n 97814 \n (541)136-4704
Annette \n Wall \n 462 Post Farm Road \n Bandon \n Oregon \n 97411 \n (541)952-5027
Gary \n Hebert \n 2983 Alexander Avenue \n Banks \n Oregon \n 97106 \n (503)937-3066
Alfonzo \n Holden \n 440 Williams Lane \n Barlow \n Oregon \n 97013 \n (503)968-7302
Loraine \n Cole \n 2819 Melville Street \n Bay City \n Oregon \n 97107 \n (503)931-4537
Selena \n Nicholson \n 4519 Reynolds Alley \n Beaverton \n Oregon \n 97000 \n (503)914-5970
Gloria \n Hatfield \n 4472 Ventura Drive \n Bend \n Oregon \n 97701 \n (541)935-9867
Mariano \n Buck \n 2940 Clousson Road \n Boardman \n Oregon \n 97818 \n (541)939-9043
Cherie \n Bird \n 13 Davis Avenue \n Bonanza \n Oregon \n 97623 \n (541)927-4312
Roland \n Dixon \n 3285 Brown Avenue \n Brookings \n Oregon \n 97415 \n (541)912-8992
Georgina \n Bowen \n 1727 Parker Drive \n Brownsville \n Oregon \n 97327 \n (541)973-9431
Alfonso \n Noel \n 985 Caynor Circle \n Burns \n Oregon \n 97720 \n (541)968-8086
Jaime \n Buck \n 3211 Green Avenue \n Butte Falls \n Oregon \n 97522 \n (541)991-3068