Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

server compilation error from client/server application

Hi guys, being new to Java I can't get my head around some differences with C++. I have a simple clent/server application written but I'm getting an error when compiling the server "cannot find symbol class Account". Three other separate classes are all compiled. I know this is staring me in the face but I would appreciate any suggestions!

package mypackage1;

import java.net.*;
import java.io.*;

public class Server
{

private int Account;

public static void main(String args[])
{

Account[] theAccounts =
{
new Account("Tom", 100f),
new Account("Richard", 200f),
new Account("Harry", 300f)
};

System.out.println("Displaying the Accounts");

theAccounts[0].display();
theAccounts[1].display();
theAccounts[2].display();

ServerSocket serverSocket = null;
try
{
serverSocket = new ServerSocket(5050);
System.out.println("Start listening on port 5050");
}
catch (IOException e)
{
System.out.println("Cannot listen on port: " + 5050 + ", " + e);
System.exit(1);
}
while (true) // infinite loop - wait for a client request
{
Socket clientSocket = null;
try
{
clientSocket = serverSocket.accept();
System.out.println("Accepted socket connection from client");
}
catch (IOException e)
{
System.out.println("Accept failed: 5050 " + e);
break;
} // create a new thread for the client
ConnectionHandler con = new ConnectionHandler(clientSocket);
if (con == null)
{
try
{
ObjectOutputStream os = new ObjectOutputStream(clientSocket.getOutputStream());
os.writeObject("error: Cannot open socket thread");
os.flush();
os.close();
}
catch (Exception ex)
{
System.out.println("Cannot send error back to client: 5050 " + ex);
}
}
else { con.init(); }
}
try
{
System.out.println("Closing server socket.");
serverSocket.close();
}
catch (IOException e)
{
System.err.println("Could not close server socket. " + e.getMessage());
}
}
}
[2824 byte] By [RugbyNut] at [2007-11-11 10:13:45]
# 1 Re: server compilation error from client/server application
Hi,

You have to import the Account class :) with its proper package. (see import java.net.*;)

If it is located in the same package you do ot need to do this but as the compoler says: I do not what is the Account you are asking me to reffer to :)
NewUniverse at 2007-11-11 22:31:45 >
# 2 Re: server compilation error from client/server application
Hello whatever error you are getting is just because your compiler cannot find the file Account.class do one thing if you have created a package import the package specifically if xyz is the package in the folder where your class is import xyz.Account;
or simply put the .class file in the classpath, set the classpath=
%classpath%;.;
if it works reply me
uday_thakare198 at 2007-11-11 22:32:51 >
# 3 Re: server compilation error from client/server application
Thanks guys for the suggestions, but it looks like a bit of a system crash and my classpath was corrupted. Classpath sorted, program running. Thanks again.
RugbyNut at 2007-11-11 22:33:49 >