gpt4 book ai didi

java - 为什么我的代码会导致空指针?

转载 作者:行者123 更新时间:2023-12-01 15:32:30 29 4
gpt4 key购买 nike

这是异常(exception):

java.lang.NullPointerException
at com.rs.net.decoders.handlers.InventoryOptionsHandler$2.run(InventoryOptionsHandler.java:512)
at com.rs.game.player.CoordsEvent.processEvent(CoordsEvent.java:55)
at com.rs.game.player.Player.processEntity(Player.java:357)
at com.rs.cores.WorldProcessor.process(WorldProcessor.java:39)
at com.rs.cores.PriorityProcessor.run(PriorityProcessor.java:10)

这是代码:

库存选项处理程序:

if (object.getId() == 15621) {
player.getWarriorsGuild().createWarrior(itemId, object);
player.getDialogueManager().startDialogue(
(short) 211,
new String[] {
"The animator hums. Something seems to be working.",
"You stand back..." });
return;
}

现在是player.java中的getWarriorsGuild()方法

public AnimationGame getWarriorsGuild() {
return warriorsGuild;
}

public AnimationGame warriorsGuild = new AnimationGame(this);

最后但并非最不重要的一点是我在 AnimationGame 中的 createWarrior 方法。

public void createWarrior(int armours, final WorldObject object) {
final WarriorsArmour sets = WarriorsArmour.forId(armours);
if (sets == null || sets.getArmour() == null) return;
if (sets.getArmour()[0] == armours || sets.getArmour()[1] == armours
|| sets.getArmour()[2] == armours) {
if (player.getInventory().containsItem(sets.getArmour()[0], 1)
&& player.getInventory().containsItem(sets.getArmour()[1],
1)
&& player.getInventory().containsItem(sets.getArmour()[2],
1)) {
final boolean running = player.isRunning();
player.getInventory().deleteItem(sets.getArmour()[0], 1);
player.getInventory().deleteItem(sets.getArmour()[1], 1);
player.getInventory().deleteItem(sets.getArmour()[2], 1);
int newX = player.getX();
int newY = player.getY() + 5;
player.setRun(false);
player.setRunHidden(false);
player.addWalkSteps(newX, newY, -1, false);
player.setNextAnimation(new Animation(827));
player.addStopDelay(3L);
player.getDialogueManager().startDialogue("WAnimator",
new Object[0]);
WorldTasksManager.schedule(new WorldTask() {

public void run() {
if (!secondloop) {
secondloop = true;
player.setRunHidden(running);
} else {
stop();
}
}

boolean secondloop;
}, 0, 6);
WorldTasksManager.schedule(new WorldTask() {

@Override
public void run() {
final NPC war = new NPC(sets.getNpcId(), new WorldTile(
object.getX(), object.getY(), 0), -1, true);
war.addWalkSteps(player.getY(), player.getY());
player.setNextFaceEntity(war);
war.setTarget(player);
war.setNextAnimation(new Animation(4166));
war.setNextForceTalk(new ForceTalk("I'M ALIVE!"));
player.getInterfaceManager().closeChatBoxInterface();
player.getInterfaceManager()
.closeReplacedRealChatBoxInterface();
player.getHintIconsManager().addHintIcon(war, 1, -1,
false);
player.sendAreaInterface(player);
WorldTasksManager.schedule(new WorldTask() {

@Override
public void run() {
war.setFinished(true);
war.setForceWalk(new WorldTile(-1, -1, -1));
World.removeNPC(war);
stop();
}

}, 60, 60);
stop();
return;
}

}, 3, 3);
} else {
return;
}
return;
}
}

我想知道,是什么导致了空指针,因为我不明白?如果您需要查看更多内容,请随时询问,谢谢:)

最佳答案

从 InventoryOptionsHandler 类检查 object.getId()。我认为你的 id 为 null 然后会导致 NullPointerException。

关于java - 为什么我的代码会导致空指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9405109/

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