I need to loop through a String with a Buffered Reader to check each character in a while loop. I need to see if there’s a character ahead before doing the while loop while still saving the character for use in the loop. I’m currently using the buffered reader’s read() that returns a char which I will then convert into a string inside the loop. There’s a line that has an error, the line is labeled in the code. The errors are: “The operator != is undefined for the argument type(s) char, null” and “Type mismatch: cannot convert from String to char” on the same line. Here’s the problematic code.
String text = t.getText();//t is a text field
BufferedReader cr = new BufferedReader(new StringReader(text));
char c;
//BUGS ON LINE BELOW
while((c=(char)cr.read())!=null) {//convert to string in here and test for different types of characters
It seems like it should work because it’s testing to see if the char is not null. Any help is appreciated!
1