Null Pointer Exception for Java Assignment
I have an assignment that I must take URLs in from a file (or standard
input if no file is given) and then count the number of times the scheme
is equal to certain things and when the domain is equal to certain things.
This is a part of my code that takes the input, splits it into the scheme
and domain, and then increases variables if certain words are found.
However, I keep getting NullPointerExceptions and I cannot find out why.
Right now, this code comes with an error at line 16. Any help would be
appreciated.
File file = new File("input");
Scanner scan = new Scanner("input");
Scanner scan2 = new Scanner(System.in);
while (!scan.next().equals("end") || !scan2.next().equals("end")){
if (scan.hasNext() == true)
url = scan.nextLine();
String[] parts = url.split(":");
scheme = parts[0];
schemeSP = parts[1];
if (scheme == "http")
httpCt++;
if (scheme == "https")
httpsCt++;
if (scheme == "ftp")
ftpCt++;
else otherSchemeCt++;
for (int j=0; j<schemeSP.length(); j++)
if (schemeSP.charAt(j) == '.')
domain = schemeSP.substring(j);
if (domain == "edu")
eduCt++;
if (domain == "org")
orgCt++;
if (domain == "com")
comCt++;
else otherDomainCt++;
fileLinesCt++;
totalLinesCt++;
}
No comments:
Post a Comment