title: ClassCastException: org.jivesoftware.smack.PacketReader$4 cannot be cast to org.jivesoftware.smackx.packet.StreamInitiation while transfering a file
body: <p>I am using Smack and Openfire server for a chat client, all things working well like chat, sending an invitation for a new addition of user, getting list of available users etc. I encountered an error of ClassCastException when I try to send a file from a android client to another user using below code it gives me stack of error.</p>
  
  <pre><code>ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
  if (sdm == null)
  sdm = new ServiceDiscoveryManager(connection);
  sdm.addFeature("http://jabber.org/protocol/disco#info");
  sdm.addFeature("jabber:iq:privacy");
  fileTransfer(fileName, recepient.getText().toString() + "/Spark 2.6.3");
  
  public void fileTransfer(String fileName, String destination) throws XMPPException   {
  
          FileTransferNegotiator.setServiceEnabled(connection,true);
          OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(destination);
          transfer.sendFile(new File(fileName), "You won't believe this!");
          try {
              Thread.sleep(10000);
          }
          catch(Exception e){
              Toast.makeText(getActivity(), "Exception " + e, Toast.LENGTH_LONG).show();
          }
          System.out.println("Status :: " + transfer.getStatus() + " Error :: " + transfer.getError() + " Exception :: " + transfer.getException());
          System.out.println("Is it done? " + transfer.isDone());
          Toast.makeText(getActivity(), "Status :: " + transfer.getStatus() + " Error :: " + transfer.getError() + " Exception :: " + transfer.getException(), Toast.LENGTH_LONG).show();
          Log.v("ONMESSAGE", "Status :: " + transfer.getStatus() + " Error :: " + transfer.getError() + " Exception :: " + transfer.getException());
      }
  </code></pre>
  
  <p>When I try to send the file, it shows up at the other end's spark however when clicked on "Accept", does not start the file transfer, instead it shows "Error in transfering file".</p>
  
  <p>In Error log it shows me the below error:</p>
  
  <pre><code>07-25 12:08:22.393: E/AndroidRuntime(27708): java.lang.ClassCastException: org.jivesoftware.smack.PacketReader$4 cannot be cast to org.jivesoftware.smackx.packet.StreamInitiation
  07-25 12:08:22.393: E/AndroidRuntime(27708):    at org.jivesoftware.smackx.filetransfer.FileTransferNegotiator.negotiateOutgoingTransfer(FileTransferNegotiator.java:401)
  07-25 12:08:22.393: E/AndroidRuntime(27708):    at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.negotiateStream(OutgoingFileTransfer.java:300)
  07-25 12:08:22.393: E/AndroidRuntime(27708):    at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.access$100(OutgoingFileTransfer.java:35)
  07-25 12:08:22.393: E/AndroidRuntime(27708):    at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer$2.run(OutgoingFileTransfer.java:214)
  07-25 12:08:22.393: E/AndroidRuntime(27708):    at java.lang.Thread.run(Thread.java:838)
  </code></pre>
  
  <p>N.B.: I am using Smack Library.</p>