I am writing a program that opens a text file and checks for comments. It then parses through the comments to check for certain words.
The error im having is with the following while loop that checks to see if the current line starts with white space or any character other than '/' if there is a non backslash character there than the while loop moves on to the next line and checks again. Once the while loop meets its requirements and breaks out the program crashes and i get the following output error.
import java.rmi.Naming;
import java.net.InetAddress;
i
import java.lang.reflect.*;
i
ERROR: String index out of range: 0
at java.lang.String.charAt(Unknown Source)
at ExtraCredit.main(ExtraCredit.java:22)</code></pre>
here is the problematic code sample
System.out.println(line);
char x = line.charAt(0);
while((line.charAt(0)!='/')&&(Character.isWhitespace(x)==false))
{
line = inputFile.nextLine();
x = line.charAt(0);
System.out.println(line);
System.out.println(x);
}
thanks for any help. Im sure its a simple error but im just not seeing it.