我的应用程序在Spark上的用户接受要传输的文件后崩溃。任何人都可以帮我找出为什么会这样吗?
我的logcat:
D/SMACK﹕ SENT (0): <iq to='myRecipient@serverip/Spark' id='87PqQ-26' type='set'><si xmlns='http://jabber.org/protocol/si' id='jsi_3460263582698459885' mime-type='image/jpeg' profile='http://jabber.org/protocol/si/profile/file-transfer'><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="IMG_20151105_142957.jpg" size="1942601" ><desc>test_file</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns='jabber:x:data' type='form'><field var='stream-method' type='list-single'><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si></iq>
D/SMACK﹕ RECV (0): <message id="6Toac-405" to="me@serverip" from="myRecipient@serverip/Spark" type="chat"><thread>k28Mi99</thread><active xmlns="http://jabber.org/protocol/chatstates"/></message>
D/SMACK﹕ RECV (0): <iq id="87PqQ-26" to="me@serverip/Smack" from="myRecipient@serverip/Spark" type="result"><si xmlns="http://jabber.org/protocol/si"><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field var="stream-method"><value>http://jabber.org/protocol/bytestreams</value><value>http://jabber.org/protocol/ibb</value></field></x></feature></si></iq>
D/SMACK﹕ SENT (0): <iq to='myRecipient@serverip/Spark' id='87PqQ-29' type='get'><query xmlns='http://jabber.org/protocol/disco#info'></query></iq>
D/SMACK﹕ RECV (0): <message id="6Toac-406" to="me@serverip" from="myRecipient@serverip/Spark" type="chat"><thread>k28Mi100</thread><inactive xmlns="http://jabber.org/protocol/chatstates"/></message><message id="6Toac-407" to="me@serverip" from="myRecipient@serverip/Spark" type="chat"><thread>k28Mi101</thread><active xmlns="http://jabber.org/protocol/chatstates"/></message>
D/SMACK﹕ RECV (0): <iq id="87PqQ-29" to="me@server/Smack" type="result" from="myRecipient@serverip/Spark"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="client" name="Smack" type="pc"/><feature var="http://jabber.org/protocol/disco#items"/><feature var="urn:xmpp:tmp:jingle"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/ibb"/><feature var="http://jabber.org/protocol/si"/><feature var="http://jabber.org/protocol/xhtml-im"/><feature var="http://jabber.org/protocol/chatstates"/><feature var="http://jabber.org/protocol/si/profile/file-transfer"/><feature var="urn:xmpp:ping"/><feature var="jabber:iq:last"/><feature var="http://jabber.org/protocol/commands"/><feature var="http://jabber.org/protocol/muc"/><feature var="http://www.xmpp.org/extensions/xep-0166.html#ns"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
D/SMACK﹕ SENT (0): <iq to='serverip' id='87PqQ-33' type='get'><query xmlns='http://jabber.org/protocol/disco#items'></query></iq>
D/SMACK﹕ RECV (0): <iq type="result" id="87PqQ-33" from="serverip" to="me@serverip/Smack"><query xmlns="http://jabber.org/protocol/disco#items"><item jid="pubsub.serverip" name="Publish-Subscribe service"/><item jid="search.serverip" name="User Search"/><item jid="proxy.serverip" name="Socks 5 Bytestreams Proxy"/><item jid="conference.serverip" name="Public Chatrooms"/></query></iq>
D/SMACK﹕ SENT (0): <iq to='pubsub.serverip' id='87PqQ-35' type='get'><query xmlns='http://jabber.org/protocol/disco#info'></query></iq>
D/SMACK﹕ RECV (0): <iq type="result" id="87PqQ-35" from="pubsub.serverip" to="me@serverip/Smack"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="pubsub" name="Publish-Subscribe service" type="service"/><feature var="http://jabber.org/protocol/pubsub"/><feature var="http://jabber.org/protocol/pubsub#access-open"/><feature var="http://jabber.org/protocol/pubsub#collections"/><feature var="http://jabber.org/protocol/pubsub#config-node"/><feature var="http://jabber.org/protocol/pubsub#create-and-configure"/><feature var="http://jabber.org/protocol/pubsub#create-nodes"/><feature var="http://jabber.org/protocol/pubsub#delete-nodes"/><feature var="http://jabber.org/protocol/pubsub#get-pending"/><feature var="http://jabber.org/protocol/pubsub#instant-nodes"/><feature var="http://jabber.org/protocol/pubsub#item-ids"/><feature var="http://jabber.org/protocol/pubsub#meta-data"/><feature var="http://jabber.org/protocol/pubsub#modify-affiliations"/><feature var="http://jabber.org/protocol/pubsub#manage-subscriptions"/><feature var="http://jabber.org/protocol/pubsub#multi-subscribe"/><feature var="http://jabber.org/protocol/pubsub#outcast-affiliation"/><feature var="http://jabber.org/protocol/pubsub#persistent-items"/><feature var="http://jabber.org/protocol/pubsub#presence-notifications"/><feature var="http://jabber.org/protocol/pubsub#publish"/><
D/SMACK﹕ RECV (0): feature var="http://jabber.org/protocol/pubsub#publisher-affiliation"/><feature var="http://jabber.org/protocol/pubsub#purge-nodes"/><feature var="http://jabber.org/protocol/pubsub#retract-items"/><feature var="http://jabber.org/protocol/pubsub#retrieve-affiliations"/><feature var="http://jabber.org/protocol/pubsub#retrieve-default"/><feature var="http://jabber.org/protocol/pubsub#retrieve-items"/><feature var="http://jabber.org/protocol/pubsub#retrieve-subscriptions"/><feature var="http://jabber.org/protocol/pubsub#subscribe"/><feature var="http://jabber.org/protocol/pubsub#subscription-options"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
D/SMACK﹕ SENT (0): <iq to='search.serverip' id='87PqQ-37' type='get'><query xmlns='http://jabber.org/protocol/disco#info'></query></iq>
D/SMACK﹕ RECV (0): <iq type="result" id="87PqQ-37" from="search.serverip" to="me@serverip/Smack"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="directory" type="user" name="User Search"/><feature var="jabber:iq:search"/><feature var="http://jabber.org/protocol/disco#info"/><feature var="http://jabber.org/protocol/rsm"/></query></iq>
D/SMACK﹕ SENT (0): <iq to='proxy.serverip' id='87PqQ-39' type='get'><query xmlns='http://jabber.org/protocol/disco#info'></query></iq>
D/SMACK﹕ RECV (0): <iq type="result" id="87PqQ-39" from="proxy.serverip" to="me@serverip/Smack"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="proxy" name="SOCKS5 Bytestreams Service" type="bytestreams"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
D/SMACK﹕ SENT (0): <iq to='conference.serverip' id='87PqQ-41' type='get'><query xmlns='http://jabber.org/protocol/disco#info'></query></iq>
D/SMACK﹕ RECV (0): <iq type="result" id="87PqQ-41" from="conference.serverip" to="me@serverip/Smack"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="conference" name="Public Chatrooms" type="text"/><identity category="directory" name="Public Chatroom Search" type="chatroom"/><feature var="http://jabber.org/protocol/muc"/><feature var="http://jabber.org/protocol/disco#info"/><feature var="http://jabber.org/protocol/disco#items"/><feature var="jabber:iq:search"/><feature var="http://jabber.org/protocol/rsm"/></query></iq>
I/System.out﹕ tcp port:7777
D/dalvikvm﹕ create interp thread : stack size=128KB
D/dalvikvm﹕ create new thread
D/dalvikvm﹕ new thread created
D/dalvikvm﹕ update thread list
D/dalvikvm﹕ threadid=31: interp stack at 0x6308b000
D/dalvikvm﹕ threadid=31: created from interp
D/dalvikvm﹕ start new thread
D/dalvikvm﹕ threadid=31: notify debugger
D/dalvikvm﹕ threadid=31 (Thread-4359): calling run()
D/SMACK﹕ SENT (0): <iq to='proxy.serverip' id='87PqQ-43' type='get'><query xmlns='http://jabber.org/protocol/bytestreams'/></iq>
D/SMACK﹕ RECV (0): <iq type="result" id="87PqQ-43" from="proxy.serverip" to="me@serverip/Smack"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost jid="proxy.175.139.183.204" port="7777"/></query></iq>
W/XMPPTCPConnection﹕ shutdownDone was not marked as successful by the writer thread
org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'.
at org.jivesoftware.smack.SynchronizationPoint.checkForResponse(SynchronizationPoint.java:253)
at org.jivesoftware.smack.SynchronizationPoint.checkIfSuccessOrWait(SynchronizationPoint.java:146)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.shutdown(XMPPTCPConnection.java:1278)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.shutdown(XMPPTCPConnection.java:503)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.instantShutdown(XMPPTCPConnection.java:492)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.notifyConnectionError(XMPPTCPConnection.java:872)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$2800(XMPPTCPConnection.java:140)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1428)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$2900(XMPPTCPConnection.java:1179)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1227)
at java.lang.Thread.run(Thread.java:841)
I/System.out﹕ [CDS]close[55522]
D/dalvikvm﹕ threadid=14: exiting
D/dalvikvm﹕ threadid=14: bye!
I/System.out﹕ close [socket][/0.0.0.0:55522]
W/AbstractXMPPConnection﹕ Connection closed with error
java.lang.NullPointerException
at org.jivesoftware.smack.util.LazyStringBuilder.length(LazyStringBuilder.java:72)
at org.jivesoftware.smack.util.LazyStringBuilder.toString(LazyStringBuilder.java:100)
at org.jivesoftware.smack.util.XmlStringBuilder.toString(XmlStringBuilder.java:344)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1377)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$2900(XMPPTCPConnection.java:1179)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1227)
at java.lang.Thread.run(Thread.java:841)
D/SMACK﹕ XMPPConnection closed due to an exception (0)
W/System.err﹕ java.lang.NullPointerException
W/System.err﹕ at org.jivesoftware.smack.util.LazyStringBuilder.length(LazyStringBuilder.java:72)
W/System.err﹕ at org.jivesoftware.smack.util.LazyStringBuilder.toString(LazyStringBuilder.java:100)
W/System.err﹕ at org.jivesoftware.smack.util.XmlStringBuilder.toString(XmlStringBuilder.java:344)
W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1377)
W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$2900(XMPPTCPConnection.java:1179)
W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1227)
W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
D/dalvikvm﹕ threadid=13: exiting
D/dalvikvm﹕ threadid=13: bye!
D/dalvikvm﹕ threadid=30: exiting
D/dalvikvm﹕ threadid=30: bye!
ProviderManager:
private void setupXMPP()
{
// must run in thread else got error
Thread thread = new Thread(new Runnable(){
public void run()
{
boolean makeConnectionSuccess = buildConnection();
if(makeConnectionSuccess)
{
ProviderManager.addIQProvider("si", "http://jabber.org/protocol/si", new StreamInitiationProvider());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
ProviderManager.addIQProvider("open", "http://jabber.org/protocol/ibb", new OpenIQProvider());
ProviderManager.addIQProvider("close", "http://jabber.org/protocol/ibb", new CloseIQProvider());
ProviderManager.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
ProviderManager.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
XMPPConn.getInstance().setXMPPConn(connection);
android.os.Message msg = connFinishHandler.obtainMessage();
connFinishHandler.handleMessage(msg);
}
}
});
thread.start();
}
登录:
public String LoginAndSetting(String username, String password)
{
String errorMsg = "ok";
usernameTempSave = username;
passwordTempSave = password;
boolean loginSuccess = userlogin(); //user login
if(loginSuccess)
{
usernameSave = usernameTempSave;
setConnection(); //receiver register
keepAlive(); //ping manager register
reenterGroupChat();
sharedPreferences = getSharedPreferences(Config.SHARED_PREFERENCES_NAME, 0);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("username", usernameTempSave);
editor.putString("password", passwordTempSave);
editor.apply();
android.os.Message msg = loginFinishHandler.obtainMessage();
loginFinishHandler.handleMessage(msg);
}
else
{
errorMsg = "Error password or username";
}
return errorMsg;
}
public boolean userlogin()
{
boolean loginSuccess = true;
if (connection != null)
{
//change user login username check
try {
boolean isConnected = connection.isConnected();
if(isConnected)
{
SASLAuthentication.unBlacklistSASLMechanism("PLAIN");
SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
connection.login(usernameTempSave,passwordTempSave);;
}
else
{
SASLAuthentication.unBlacklistSASLMechanism("PLAIN");
SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
connection.connect().login(usernameTempSave,passwordTempSave);;
}
loginSuccess = true;
} catch (SmackException e) {
loginSuccess = false;
e.printStackTrace();
} catch (IOException e) {
loginSuccess = false;
e.printStackTrace();
} catch (XMPPException e) {
loginSuccess = false;
e.printStackTrace();
}
}
//findUser("");
return loginSuccess;
}
选择文件然后转移:
private void selectImage()
{
Bitmap bitmap = null;
bitmap = BitmapFactory.decodeFile("/storage/sdcard1/DCIM/Camera/IMG_20151105_142957.jpg");
ImageView image = (ImageView)findViewById(R.id.image);
image.setImageBitmap(bitmap);
selectedImagePath = "/storage/sdcard1/DCIM/Camera/IMG_20151105_142957.jpg";
System.out.println(selectedImagePath);
fileTransfer(selectedImagePath);
}
public void fileTransfer(String filenameWithPath) {
FileTransferManager manager = FileTransferManager.getInstanceFor(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(friendId + "@serverip/Spark");
File file = new File(filenameWithPath);
try {
transfer.sendFile(file, "test_file");
} catch (SmackException e) {
e.printStackTrace();
}
while (!transfer.isDone()) {
if (transfer.getStatus().equals(FileTransfer.Status.error)) {
System.out.println("ERROR!!! " + transfer.getError());
} else if (transfer.getStatus().equals(FileTransfer.Status.cancelled)
|| transfer.getStatus().equals(FileTransfer.Status.refused)) {
System.out.println("Cancelled!!! " + transfer.getError());
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (transfer.getStatus().equals(FileTransfer.Status.refused) || transfer.getStatus().equals(FileTransfer.Status.error)
|| transfer.getStatus().equals(FileTransfer.Status.cancelled)) {
System.out.println("refused cancelled error " + transfer.getError());
} else {
System.out.println("Success");
}
}
我所知道的是,当尝试编写要发送到服务器端的xml时,会返回NullPointerException。我不知道为什么它将返回null并且因为它返回null,它会导致我的XMPPConnection连接关闭。
感谢任何反馈。