title: Receiving user defined Object over TCP with ClassNotFoundException
body: <p>I'm developing a client/server application that uses TCP connection. I need to send a user defined object from server to client. everything is working fine until the client receives the object, it throws the ClassNotFoundException even though the class is on both sides and I cast it, and it is Serializable. </p>
  
  <p>The exception at client side is:</p>
  
  <pre><code>     Exception in thread "main" java.lang.ClassNotFoundException: jggserver.Question
  </code></pre>
  
  <p>I don't know why the client is casting using the server package. (they are different projects).</p>
  
  <p>here is the code at client side, where the exception is: </p>
  
  <pre><code>    q = (Question) clientInputStream.readObject();
  </code></pre>
  
  <p>code at server side:</p>
  
  <pre><code>    serverOutputStream.writeObject(question);
  </code></pre>
  
  <p>Although I went through several tutorials and they do the exact thing. </p>
  
  <p>I appreciate any help.</p>
  
  <hr>
  
  <p>COMMENTS: </p>
  
  <p>user1697575, both programs are on the same computer and same IDE (netbeans).</p>
  
  <ul>
  <li><p>I don't know about the TCP payload, I will search about it.</p></li>
  <li><p>I create the class on the server then refactor it on the client, I don't know if it's the correct way or not.</p></li>
  <li><p>I can't use RMI because I'm asked to specifically use this way to implement my project. </p></li>
  </ul>
  
  <p>many thanks.</p>
  
  <hr>
  
  <p>SOLVED: I created a separate package and added Question class to it, then I included this package in the server and the client programs. </p>
  
  <p>thank you all guys, specially Juan.</p>