server compilation error from client/server application


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: server compilation error from client/server application

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Location
    Ireland
    Posts
    2

    Red face 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!

    Code:
    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());
            }
        }
    }
    Steve

  2. #2
    Join Date
    Mar 2004
    Posts
    78
    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

  3. #3
    Join Date
    Dec 2006
    Location
    pune
    Posts
    4

    about symbol not found

    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

  4. #4
    Join Date
    Jan 2007
    Location
    Ireland
    Posts
    2

    Smile

    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.
    Steve

Similar Threads

  1. Replies: 2
    Last Post: 08-04-2007, 12:12 PM
  2. Replies: 1
    Last Post: 09-19-2006, 08:17 PM
  3. Replies: 3
    Last Post: 06-02-2006, 09:00 PM
  4. .NET Application Server.?
    By Aaron Sevivas in forum .NET
    Replies: 0
    Last Post: 04-23-2002, 07:39 AM
  5. New!! Web Application Server --> SkunkWeb
    By Juan Carlos Leon ( jcleon ) in forum web.announcements
    Replies: 0
    Last Post: 08-26-2001, 10:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center