nullpointer 예외가 있습니다. 해결할 수없는 예외가 있습니다. 여러분이보기에 좋을 것 같습니다. PlayerUpdateTask의 84알 수없는 nullpointer 예외 - Java
java.lang.NullPointerException
at org.ikov.engine.task.impl.PlayerUpdateTask.execute(PlayerUpdateTask.java:84)
at org.ikov.engine.task.ParallelTask$1.run(ParallelTask.java:44)
at org.ikov.engine.GameEngine$4.run(GameEngine.java:160)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
라인 : 다음 nullpointer하지 않는 :
if(player.getLocalPlayers() == null) {
player.disconnected = true;
return;
}
List<Integer> localPlayerList = new ArrayList<Integer>(player.getLocalPlayers());
/*
* If the map region changed send the new one. We do this immediately as
* the client can begin loading it before the actual packet is received.
*/
if (player.mapRegionDidChange) {
player.getActionSender().sendMapRegion();
}
/*
* The update block packet holds update blocks and is send after the
* main packet.
*/
GamePacketBuilder updateBlock = new GamePacketBuilder();
/*
* The main packet is written in bits instead of bytes and holds
* information about the local list, players to add and remove, movement
* and which updates are required.
*/
GamePacketBuilder packet = new GamePacketBuilder(81,
GamePacket.Type.VARIABLE_SHORT);
packet.startBitAccess();
/*
* Updates this player.
*/
updateThisPlayerMovement(packet);
updatePlayer(updateBlock, player, false, true);
/*
* Write the current size of the player list.
*/
packet.putBits(8, localPlayerList.size());
//Set up a deletion queue
List<Integer> deletionQueue = new ArrayList<Integer>();
/*
* Iterate through the local player list.
*/ - FROM HERE THE NULLPOINTER starts
주의 사항이
for (int other : localPlayerList) {
코드 최대 이것은 내가 받고있어 예외 항상 일어난다, 그것은 때때로 일어난다. 그러나 나는 그것을 소트하고 싶다. 너희들은 어떤 생각을 가지고 있니, 나는 localPlayerList가 null 일 수 있다는 것을 이해하지 못한다. 이것은 자바 게임을위한 것입니다. 여기
로컬 플레이어 목록이 채워집니다 방법은 다음과 같습니다 가능성이 이유는 localPlayerList
가 null
인 Integer
포함되어 있다는 것입니다 많이
//We keep track of the amount of players we've added, we want to keep it down a bit as we don't want to loverload people's client
int addedPlayers = 0;
/*
* Loop through every player.
*/
for (Player otherPlayer : PlayerManager.getSingleton().getPlayers()) {
if (otherPlayer == null) {
continue;
}
if (!player.activatedPlayerUpdate) {
break;
}
if (!player.withinDistance(otherPlayer)) {
/*
* Check that the Player is within good distance of the player
* before adding to local list.
*/
continue;
}
/*
* Check if there is room left in the local list.
*/
if (player.getLocalPlayers().size() >= 255 || addedPlayers >= 20) {
/*
* There is no more room left in the local list. We cannot add
* more players, so we just ignore the extra ones. They will be
* added as other players get removed.
*/
break;
}
/*
* Do not add anymore data to the packet if it the packet exceeds
* the maximum packet size as this will cause the client to crash.
*/
if (packet.getLength() + updateBlock.getLength() >= 3072) {
break;
}
/*
* If they should not be added ignore them.
*/
if (otherPlayer == player
|| player.getLocalPlayers()
.contains(otherPlayer.getIndex())
|| !otherPlayer.isVisible()
|| otherPlayer.getMapInstance() != player.getMapInstance()) {
continue;
}
/*
* Add the player to the local list if it is within distance.
*/
player.getLocalPlayers().add(otherPlayer.getIndex());
addedPlayers++;
/*
* Add the player in the packet.
*/
addNewPlayer(packet, otherPlayer);
/*
* Update the player, forcing the appearance flag.
*/
updatePlayer(updateBlock, otherPlayer, true, false);
}
/*
* Check if the update block is not empty.
*/
if (!updateBlock.isEmpty()) {
/*
* Write a magic id indicating an update block follows.
*/
packet.putBits(11, 2047);
packet.finishBitAccess();
/*
* Add the update block at the end of this packet.
*/
packet.put(updateBlock.toPacket().getPayload());
} else {
/*
* Terminate the packet normally.
*/
packet.finishBitAccess();
}
/*
* Write the packet.
*/
player.write(packet.toPacket());
감사합니다,
데이비드
정확하게 무엇이 진행되고 있는지를 알려면'player.getLocalPlayers()'리스트가 어떻게 채워지는지 정말로 알아야합니다. 그러나 분명히 말했듯이, 그 안에는 null이 있습니다. – Radiodef
추가했습니다. 고맙습니다. – user3475308