Hi folks,
I am a java newby, need to implement a project for work using java, and am getting a compiler error that I don't understand the reason for.
Here is the error from the compiler:
Code:
symbol : method read(byte[],int,int)
location: class java.io.BufferedReader
oStreamIn.read( sRxBuf, 0, sRxBuf.length );
1 error
BUILD FAILED (total time: 0 seconds)
I am trying to use the BufferedReader class to read in some data from a socket into a predefined byte array. Below is the relavent code:
Code:
import java.net.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CommInterface {
private Socket oSocketFD = null;
private PrintWriter oStreamOut = null;
private BufferedReader oStreamIn = null;
private byte[] sRxBuf = new byte[2048];
private int receiveServerMsg()
{
.
.
.
// Attempt to receive a message from the server
oStreamIn.read( sRxBuf, 0, sRxBuf.length );
.
.
.
// And return
return( 0 );
}
public int openConnectionToServer( String sServer, int nPort )
{
// Attempt to connect and log in to the server
try
{
oSocketFD = new Socket( sServer, nPort );
oStreamOut = new PrintWriter( oSocketFD.getOutputStream(), true );
oStreamIn = new BufferedReader( new InputStreamReader(oSocketFD.getInputStream()) );
}
catch (UnknownHostException e)
{
oSocketFD = null;
oStreamOut = null;
oStreamIn = null;
System.err.println( "Don't know about host: " + sLMCSServer );
System.exit( 1 );
}
catch (IOException e)
{
oSocketFD = null;
oStreamOut = null;
oStreamIn = null;
System.err.println( "Couldn't get I/O for the connection to: " + sLMCSServer );
System.exit( 1 );
}
// And return
return( 0 );
}
}
The compilation error occurs on the "oStreamIn.read( sRxBuf, 0, sRxBuf.length );" line.
I have googled for various "cannot find symbol" java compilation error messages but I don't seem to be able to see anything that makes sense in my context (probably due to my lack of java experience).
I would welcome any suggestions anyone can offer to try and explain to me why the error is being generated, and how to resolve it.