gpt4 book ai didi

java - NullPointerException 致命异常 : Thread-5023 error

转载 作者:行者123 更新时间:2023-11-29 21:06:24 24 4
gpt4 key购买 nike

我正在尝试在 android 上创建一个 xmpp/jabber 客户端,我正在使用“对话”的开源代码,现在我遇到了以下错误。

我尝试过搜索但得到了不同的答案,我确实知道该值不为空,因为我在崩溃前将它打印到屏幕上,我在 android/java 场景中仍然很陌生并且不熟悉线程错误。

据我了解,可能是线程更新ui导致的,但找不到确切的问题。

日志:

06-24 16:13:27.287    9388-9415/com.test E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-5023
Process: com.test, PID: 9388
java.lang.NullPointerException
at com.test.entities.MucOptions.processPacket(MucOptions.java:131)
at com.test.parser.PresenceParser.parseConferencePresence(PresenceParser.java:35)
at com.test.services.XmppConnectionService$5.onPresencePacketReceived(XmppConnectionService.java:275)
at com.test.xmpp.XmppConnection.processPresence(XmppConnection.java:414)
at com.test.xmpp.XmppConnection.processStream(XmppConnection.java:303)
at com.test.xmpp.XmppConnection.processStream(XmppConnection.java:244)
at com.test.xmpp.XmppConnection.switchOverToTls(XmppConnection.java:516)
at com.test.xmpp.XmppConnection.processStream(XmppConnection.java:236)
at com.test.xmpp.XmppConnection.connect(XmppConnection.java:175)
at com.test.xmpp.XmppConnection.run(XmppConnection.java:219)
at java.lang.Thread.run(Thread.java:841)

MucOptions:131

item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");

完成 MucOptions.java:

public void processPacket(PresencePacket packet, PgpEngine pgp) {


String[] fromParts = packet.getFrom().split("/");
if (fromParts.length>=2) {
String name = fromParts[1];



Log.i("MUC packet", packet.toString()+"");
String type = packet.getAttribute("type");
Element item;
if (type==null) {
User user = new User();

item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");
user.setName(name);
user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role"));
user.setName(name);
if (name.equals(getNick())) {
this.isOnline = true;
this.error = 0;
self = user;
} else {
addUser(user);
}
if (pgp != null) {
Element x = packet.findChild("x",
"jabber:x:signed");
if (x != null) {
Element status = packet.findChild("status");
String msg;
if (status != null) {
msg = status.getContent();
} else {
msg = "";
}
user.setPgpKeyId(pgp.fetchKeyId(account,msg, x.getContent()));
}
}
} else if (type.equals("unavailable")) {
if (name.equals(getNick())) {
item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");
String nick = item.getAttribute("nick");
if (nick!=null) {
aboutToRename = false;
if (renameListener!=null) {
renameListener.onRename(true);
}
this.setNick(nick);
}
}
deleteUser(packet.getAttribute("from").split("/")[1]);
} else if (type.equals("error")) {
Element error = packet.findChild("error");
if (error.hasChild("conflict")) {
if (aboutToRename) {
if (renameListener!=null) {
renameListener.onRename(false);
}
aboutToRename = false;
} else {
this.error = ERROR_NICK_IN_USE;
}
}
}
}
}

最佳答案

如果 item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item"); 是你的第 131 行,然后 packetpacket.findChild("x","http://jabber.org/protocol/muc#user")null.

用这样的东西检查它:

if (packet == null) {
throw new NullPointerException("packet is null")
} else if (packet.findChild("x","http://jabber.org/protocol/muc#user") == null) {
throw new NullPointerException("packet.findChild(\"x\",\"http://jabber.org/protocol/muc#user\") is null")
}
item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");

关于java - NullPointerException 致命异常 : Thread-5023 error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24389295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com