Results 1 to 2 of 2
  1. #1
    srivigneshwar is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default Help with chat client program

    Hi I unable to find the cause of this note when i compile

    Java Code:
    Note: ChatClient.java uses or overrides a deprecated API
    Note: Recompile with -deprecation for details
    When I try to run the program i gt the following error
    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at ChatClient .main <ChatClient.java: 76>

    Here is the program,
    Java Code:
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    class ChatClient extends Frame implements Runnable
    {
    	Socket soc;
    	TextField tf;
    	TextArea ta;
    	Button btnSend,btnClose;
    	String sendTo;
    	String LoginName;
    	Thread t=null;
    	DataOutputStream dout;
    	DataInputStream din;
    
    	ChatClient(String LoginName,String chatwith) throws Exception
    	{
    		super(LoginName);
    		this.LoginName=LoginName;
    		sendTo=chatwith;
    		tf=new TextField(50);
    		ta=new TextArea(50,50);
    		btnSend= new Button("Send");
    		btnClose = new Button("Close");
    		soc=new Socket("127.0.0.1",5217);
    
    		din=new DataInputStream(soc.getInputStream());
    		dout=new DataOutputStream(soc.getOutputStream());
    		dout.writeUTF(LoginName);
    		
    		t=new Thread(this);
    		t.start();
    	}
    	void setup()
    	{
    		setSize(600,400);
    		setLayout(new GridLayout(2,1));
    		add(ta);
    		Panel p=new Panel();
            p.add(tf);
    		p.add(btnSend);
    		p.add(btnClose);
    		add(p);
    		show();
    	}
    
    	public boolean action(Event e, Object o)
    	{
    		if(e.arg.equals("Send"))
    		{
    			try
    			{
    				dout.writeUTF(sendTo+" 
    
    "+tf.getText().toString());
    				
    
    ta.append("\n"+LoginName+"Says:"+tf.getText().toString());
    				tf.setText("");
    			 }
    			catch(Exception ex)
    			     {}
    		  }
    			else if(e.arg.equals("Close"))
    			{
    				try
    				{
    					
    
    dout.writeUTF(LoginName+"LOGOUT");
    					System.exit(1);
    				}
    				catch (Exception ex)
    				   {}
    			}
    			return super.action(e,o);
    		}
    
        public static void main(String args[]) throws Exception 
    	{
    		ChatClient Client1=new ChatClient( args[0],args[1]);
                                    
    		Client1.setup();
    	}
       public void run()
    		{
    	     while(true)
    			{
    			 try
    			 {
    				ta.append("\n"+sendTo+"Says:"+din.readUTF());
    			 }
    			 catch (Exception ex)
    			 {
    				 ex.printStackTrace();
    			 }
    			}
    		}
    	}

    Please help me with this..
    Thanks in advance!

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    your two problems are unrelated.

    1. deprecation warning: compile with the -deprecation flag so you know what is obsolete and find out what you should replace it with.
    2. array index out of bounds exception: something in your main method is accessing a bad index in an array. i suspect it is due to you not passing in adequate arguments when running the program (which you should check for before doing anything else anyways).

Similar Threads

  1. Chat Client
    By Jessi34 in forum New To Java
    Replies: 5
    Last Post: 12-09-2009, 03:49 PM
  2. Multithread Chat server/client
    By gwaldarick in forum Advanced Java
    Replies: 3
    Last Post: 09-19-2009, 12:22 AM
  3. Multi-user chat server and client
    By 435.mahesh in forum Java Software
    Replies: 6
    Last Post: 04-25-2009, 12:45 AM
  4. Multi Client/Server Chat Question
    By Kodak07 in forum Networking
    Replies: 3
    Last Post: 03-29-2009, 10:50 PM
  5. Replies: 2
    Last Post: 12-27-2008, 08:02 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
  •