LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2009, 02:17 PM   #1
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Getting cannot find symbol error compiling java code using NetBeans 6.5 IDE


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.
 
Old 02-13-2009, 04:43 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I think what the compiler really means is "parameter mismatch".

Specifically, here's the method:
Quote:
int read(char[] cbuf, int off, int len)
Read characters into a portion of an array.
To use it, you should declare "char[] sRxBuf = new char[2048];" (instead of "byte").

Of course, that might cause other problems.

One way around it is to use "InputStream" (which supports a "read" from a byte array).

I'd also recommand looking into "FileChannel" I/O, in the separate "java.nio" package:
http://www.java2s.com/Code/JavaAPI/j...eBufferbuf.htm

'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java + Netbeans installation error tm2383 Linux - Software 1 12-23-2007 08:04 AM
Java "Cannot Find Symbol" radicaledward Programming 2 05-19-2006 01:00 AM
Installing netbeans IDE linuxmandrake Debian 3 11-02-2005 07:25 AM
configure a browser on netbeans ide pelegk2 Linux - Software 0 10-11-2004 04:49 AM
Java: Netbeans IDE question ludeKing Programming 0 09-01-2004 09:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration