问题描述
packagepractice.Socket;importjava.io.DataInputStream;importjava.io.DataOutputStream;importjava.io.IOException;importjavax.microedition.io.Connector;importjavax.microedition.io.ServerSocketConnection;importjavax.microedition.io.SocketConnection;importjavax.microedition.lcdui.Command;importjavax.microedition.lcdui.CommandListener;importjavax.microedition.lcdui.Display;importjavax.microedition.lcdui.Displayable;importjavax.microedition.lcdui.Form;importjavax.microedition.lcdui.TextField;importjavax.microedition.midlet.MIDlet;importjavax.microedition.midlet.MIDletStateChangeException;publicclassChatServerMIDlerextendsMIDletimplementsCommandListener,Runnable{privateServerSocketConnectionssc=null;privateSocketConnectionsc=null;privateDataInputStreamdis=null;privateDataOutputStreamdos=null;privateTextFieldtf=newTextField("","",255,TextField.ANY);privateCommandcmdsend=newCommand("发送",Command.OK,1);privateDisplaydisplay;privateFormform=newForm("聊天界面");privatebooleanflag=true;publicChatServerMIDler(){display=Display.getDisplay(this);}protectedvoidstartApp()throwsMIDletStateChangeException{display.setCurrent(form);form.append(tf);form.addCommand(cmdsend);form.setCommandListener(this);try{ssc=(ServerSocketConnection)Connector.open("socket://:9999");sc=(SocketConnection)ssc.acceptAndOpen();dis=sc.openDataInputStream();dos=sc.openDataOutputStream();newThread(this).start();}catch(Exceptione){e.printStackTrace();}}publicvoidcommandAction(Commandc,Displayabled){if(c==cmdsend){try{//dos=sc.openDataOutputStream();dos.writeUTF(tf.getString());}catch(Exceptione){e.printStackTrace();}}}protectedvoiddestroyApp(booleanarg0)throwsMIDletStateChangeException{}publicvoidclose(){try{ssc.close();sc.close();dis.close();dos.close();}catch(Exceptione){e.printStackTrace();}}protectedvoidpauseApp(){}publicvoidrun(){while(flag){try{//dis=sc.openDataInputStream();Stringmsg=dis.readUTF();form.append(msg+"n");}catch(Exceptione){e.printStackTrace();}}close();}}packagepractice.Socket;importjava.io.DataInputStream;importjava.io.DataOutputStream;importjava.io.IOException;importjavax.microedition.io.Connector;importjavax.microedition.io.ServerSocketConnection;importjavax.microedition.io.SocketConnection;importjavax.microedition.lcdui.Command;importjavax.microedition.lcdui.CommandListener;importjavax.microedition.lcdui.Display;importjavax.microedition.lcdui.Displayable;importjavax.microedition.lcdui.Form;importjavax.microedition.lcdui.TextField;importjavax.microedition.midlet.MIDlet;importjavax.microedition.midlet.MIDletStateChangeException;publicclassChatClientMIDletextendsMIDletimplementsCommandListener,Runnable{privateTextFieldtf=newTextField("","",50,TextField.ANY);privateCommandcmdsend=newCommand("发送",Command.OK,1);privateDisplaydisplay;privateFormform=newForm("聊天");privatebooleanflag=true;SocketConnectionsc=null;DataInputStreamdis=null;DataOutputStreamdos=null;publicChatClientMIDlet(){display=Display.getDisplay(this);}protectedvoidstartApp()throwsMIDletStateChangeException{display.setCurrent(form);form.append(tf);form.addCommand(cmdsend);form.setCommandListener(this);try{sc=(SocketConnection)Connector.open("socket://127.0.0.1:9999");dis=sc.openDataInputStream();dos=sc.openDataOutputStream();newThread(this).start();}catch(Exceptione){e.printStackTrace();}}publicvoidclose(){try{//ssc.close();sc.close();dis.close();dos.close();}catch(Exceptione){e.printStackTrace();}}publicvoidcommandAction(Commandc,Displayabled){if(c==cmdsend){try{//dos=sc.openDataOutputStream();dos.writeUTF(tf.getString());}catch(Exceptione){e.printStackTrace();}}}protectedvoiddestroyApp(booleanarg0)throwsMIDletStateChangeException{}protectedvoidpauseApp(){}publicvoidrun(){while(flag){try{//dis=sc.openDataInputStream();Stringmsg=dis.readUTF();form.append(msg+"n");}catch(Exceptione){e.printStackTrace();}}close();}//}}有谁帮忙看下程序总是抛出异常!帮忙解决下!谢谢!
解决方案
解决方案二:
哪句抛异常?异常贴出来!
解决方案三:
mark!~!~!
解决方案四:
就是关闭模拟器时候抛异常!
解决方案五:
就是关闭模拟器时候抛出的异常!
解决方案六:
客户端模拟器还是服务端模拟器?
解决方案七:
估计是线程死亡的时候抛出的异常
解决方案八:
请问抛出什么异常?客户端还是服务器端?
解决方案九:
关闭客户端就会抛出异常!抛IO异常!
解决方案十:
该回复于2010-12-02 09:30:36被版主删除