Results 1 to 2 of 2
Thread: Help with chat client program
- 04-03-2009, 05:43 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 1
- Rep Power
- 0
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
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!
- 04-03-2009, 07:32 PM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 13
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
-
Chat Client
By Jessi34 in forum New To JavaReplies: 5Last Post: 12-09-2009, 04:49 PM -
Multithread Chat server/client
By gwaldarick in forum Advanced JavaReplies: 3Last Post: 09-19-2009, 01:22 AM -
Multi-user chat server and client
By 435.mahesh in forum Java SoftwareReplies: 6Last Post: 04-25-2009, 01:45 AM -
Multi Client/Server Chat Question
By Kodak07 in forum NetworkingReplies: 3Last Post: 03-29-2009, 11:50 PM -
Chat program: how server distinguishes each client connected to it
By kathleenr in forum NetworkingReplies: 2Last Post: 12-27-2008, 09:02 PM
Bookmarks