I'm trying to input some addresses from an online text file, but there are errors I don't understand when running the code.
The errors are:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at Main.main(Main.java:20)
What am doing wrong?
I opened the text of the url with the browser and it opens right(Problem is not with the connection or the link)
I'm Using Windows command prompt
import java.net.URL;
import java.util.Scanner;
class Address
{
String street;
String city;
String state;
int zip;
}
public class WebAddresses
{
public static void main(String[] args) throws Exception
{
URL addys = new URL("http://cs.leanderisd.org/txt/fake-addresses.txt");
Scanner fin = new Scanner( addys.openStream() );
Address uno = new Address();
uno.street = fin.nextLine(); //line 20
uno.city = fin.nextLine();
uno.state = fin.next();
uno.zip = fin.nextInt();
fin.skip("\n");
Address dos = new Address();
dos.street = fin.nextLine();
dos.city = fin.nextLine();
dos.state = fin.next();
dos.zip = fin.nextInt();
fin.skip("\n");
Address tre = new Address();
tre.street = fin.nextLine();
tre.city = fin.nextLine();
tre.state = fin.next();
tre.zip = fin.nextInt();
fin.skip("\n");
fin.close();
System.out.println(uno.street + ", " + uno.city + ", " + uno.state + " " + uno.zip);
System.out.println(dos.street + ", " + dos.city + ", " + dos.state + " " + dos.zip);
System.out.println(tre.street + ", " + tre.city + ", " + tre.state + " " + tre.zip);
}
}