我正在使用 xmpp 进行文件传输。这是我的文件传输代码。
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
if (sdm == null)
sdm = new ServiceDiscoveryManager(connection);
FileTransferManager manager = new FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("user@myHost/Smack");
File file = new File(filenameWithPath);
try {
transfer.sendFile(file, "You won't believe this!");
} catch (XMPPException e) {
e.printStackTrace();
}
while (!transfer.isDone()) {
Log.i("progres", "" + transfer.getProgress());
}
if (transfer.getStatus().equals(Status.refused)|| transfer.getStatus().equals(Status.error) || transfer.getStatus().equals(Status.cancelled))
{
System.out.println("refused cancelled error " + transfer.getError());
} else
{
System.out.println("Success");
}
问题是当对方接受文件时它会崩溃。
日志文件:
FATAL EXCEPTION: File Transfer jsi_1117022495316866568
java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2
at org.jivesoftware.smackx.filetransfer.FileTransferNegotiator.negotiateOutgoingTransfer(FileTransferNegotiator.java:401)
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.negotiateStream(OutgoingFileTransfer.java:359)
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.access$100(OutgoingFileTransfer.java:35)
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer$2.run(OutgoingFileTransfer.java:214)
at java.lang.Thread.run(Thread.java:1019)