Java 线程与writeUTF方法的问题 80
我写了一个socket套接字通信的程序,发送端将String用writeUTF方法写入到输出流.接收端(MultiThread)传过来的String,作处理,再发送回发送...
我写了一个socket套接字通信的程序,发送端将String用writeUTF方法写入到输出流.接收端(MultiThread)传过来的String,作处理,再发送回发送端.运行时出现了如下问题:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "hi"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at NetProTest.Client$ButtonListener.actionPerformed(Client.java:45)
at javax.swing.JTextField.fireActionPerformed(Unknown Source)
at javax.swing.JTextField.postActionEvent(Unknown Source)
at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
请教高手帮下忙解决下,感激不尽!!
hi 是从JTextField输入的要发送出去的字符串..我是用writeUTF()将 hi 写出去的 接收端接收 hi 这上字符串 展开
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "hi"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at NetProTest.Client$ButtonListener.actionPerformed(Client.java:45)
at javax.swing.JTextField.fireActionPerformed(Unknown Source)
at javax.swing.JTextField.postActionEvent(Unknown Source)
at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
请教高手帮下忙解决下,感激不尽!!
hi 是从JTextField输入的要发送出去的字符串..我是用writeUTF()将 hi 写出去的 接收端接收 hi 这上字符串 展开
4个回答
展开全部
java.lang.NumberFormatException 这个异常已经说的很清楚了,应该是你的哪里调用了了类型转换所致,可以查找一下Double.parseDouble(String s)。在这个转换前加上try catch,打出异常,和你的writeUTF应该没关系吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
java.lang.Double.parseDouble(Unknown Source),我认为应该是你没按协议去读写,程序中应该获取一个double的,但是你读到字符串"hi"了
//=====================================
那就不应该读一个double了,而是readUTF了
//=====================================
那就不应该读一个double了,而是readUTF了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很明显,由于你的程序中有Double.parseDouble(str),所以从JTextField输入的内容就必须为数字,否则就会出现这个格式转化异常,除非你自己做一些判断来绕开
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你到底是接收端出了这个问题 还是发送端出了这个问题啊
看异常是你在按按钮的时候对字符串做了parseDouble(String s)的调用
而你的s为hi 所以出现numberformatexception异常
看异常是你在按按钮的时候对字符串做了parseDouble(String s)的调用
而你的s为hi 所以出现numberformatexception异常
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询