Suraya Suraya - 5 months ago 8
Java Question

.class expected in Java?

I am trying to get the next char for my scanner.

My constructor is :

public S(InputStream inStream)
{
in = new BufferedReader(new InputStreamReader(inStream));
e = false; // if input stream is done
getNextChar();
}


my method is:.

private void getNextChar()
{
int data = in.read();
char temp = char (data);
currentChar = temp;
}


I am getting a
'.class' expected error in "getNextChar()"


Any ideas why?

Answer
private void getNextChar() throws IOException
{
    int data = in.read(); 
    char temp = (char) data;
    currentChar = temp;
}

casting should be done like this: char temp = (char) data;

Not like this: char temp = char (data);