2012-03-29 10 views
0

は、以下がそのオブジェクト私が合格しようとしているカスタムクラス、あるスロー:関連私はソケットを通じてカスタムクラスのオブジェクトを送信しようとしていますが、それは「java.io.NotSerializableException」

package dataEx; 

    import java.io.Serializable; 
    import java.util.*; 

    public class dataToExchange implements Serializable 
    { 


     public Integer frameIndex; 
     public Integer xOffsetTank; 

    } 

dataToExchange data=new dataToExchange() ; 
    data.frameIndex=2; 
    data.xOffsetTank=23; 
    output.writeObject(data); 

サーバーオブジェクトを受信し、

data_recv=(dataToExchange)input.readObject(); 
    System.out.println(data_recv.xOffsetTank); 
01を印刷:データは私が通過しようとしているオブジェクトがwriteObjectメソッドによって、あるクライアントコード、

スタックトレース:

java.io.NotSerializableException: dataEx.proclient$dataToExchange 
    at java.io.ObjectOutputStream.writeObject0(Unknown Source) 
    at java.io.ObjectOutputStream.writeObject(Unknown Source) 
    at dataEx.proclient.SendTheChange(proclient.java:283) 
    at dataEx.proclient.keyDown(proclient.java:256) 
    at java.awt.Component.handleEvent(Unknown Source) 
    at java.awt.Component.postEvent(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.Component.dispatchEvent(Unknown Source) 
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$000(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(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) 
java.net.SocketException: Connection reset by peer: socket write error 
    at java.net.SocketOutputStream.socketWrite0(Native Method) 
    at java.net.SocketOutputStream.socketWrite(Unknown Source) 
    at java.net.SocketOutputStream.write(Unknown Source) 
    at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source) 
    at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source) 
    at java.io.ObjectOutputStream.writeFatalException(Unknown Source) 
    at java.io.ObjectOutputStream.writeObject(Unknown Source) 
    at dataEx.proclient.SendTheChange(proclient.java:283) 
    at dataEx.proclient.keyDown(proclient.java:256) 
    at java.awt.Component.handleEvent(Unknown Source) 
    at java.awt.Component.postEvent(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.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$000(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(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) 
java.net.SocketException: Connection reset by peer: socket write error 
    at java.net.SocketOutputStream.socketWrite0(Native Method) 
    at java.net.SocketOutputStream.socketWrite(Unknown Source) 
    at java.net.SocketOutputStream.write(Unknown Source) 
    at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source) 
    at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source) 
    at java.io.ObjectOutputStream.writeNonProxyDesc(Unknown Source) 
    at java.io.ObjectOutputStream.writeClassDesc(Unknown Source) 
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) 
    at java.io.ObjectOutputStream.writeObject0(Unknown Source) 
    at java.io.ObjectOutputStream.writeFatalException(Unknown Source) 
    at java.io.ObjectOutputStream.writeObject(Unknown Source) 
    at dataEx.proclient.SendTheChange(proclient.java:283) 
    at dataEx.proclient.keyDown(proclient.java:256) 
    at java.awt.Component.handleEvent(Unknown Source) 
    at java.awt.Component.postEvent(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.Component.dispatchEvent(Unknown Source) 
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$000(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(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) 

答えて

0

間違ったクラス。例外を再度確認してください。 'dataToExchange'というクラスをシリアル化しようとしていますが、その定義は 'proclient'クラスの中にネストされていますが、Serializableではありません。同じ名前の2つのクラスがあることを見落としましたが、これは悪い考えであることが実証されています。

+0

あなたは正しいです!どうもありがとうございました。私はもともとdataToExchangeをサーバーとクライアントの両方に対して別々に行ったのですが、共通のクラスがそこにあるはずですが、Ctrlキーを押しながらコードをn回押すと、前のdataToExchangeのコピーを削除するのを忘れていました。私の右に役立つ、私はスタックトレースにもっと注意を払う必要があります、そのサイズを見て私はそれを介してスキミング、今私はその重要性を知っている。もう一度感謝します。あなたは私の不満を終わらせました。そして、私がソケットで始まったばかりなので、あなたは私をたくさん助けました。 –

関連する問題