out of the code provided, which is line 2315?
|
This is the code
if (npcs[i].isDead == true) {
if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) {
npcs[i].updateRequired = true;
npcs[i].facePlayer(0);
npcs[i].killedBy = getNpcKillerId(i);
npcs[i].animNumber = getDeadEmote(i); // dead emote
npcs[i].animUpdateRequired = true;
npcs[i].freezeTimer = 0;
npcs[i].applyDead = true;
killedBarrow(i);
if (isZombieCaveNpc(i))
killedZombies(i);
if (isFightCaveNpc(i))
killedTzhaar(i);
if(npcs[i].summon == true)
npcs[i].summon = false;
npcs[i].actionTimer = 4; // delete time
resetPlayersInCombat(i);
/*if (npcs[i].npcType == 1158){
handleKalpite(i);
}*/Help Please.Code:private void killedZombies(int i) { final Client c2 = (Client)Server.playerHandler.players[npcs[i].spawnedBy]; c2.zombiesKilled++; System.out.println("To kill: " + c2.zombiesToKill + " killed: " + c2.zombiesKilled); if (c2.zombiesKilled == c2.zombiesToKill) { //c2.sendMessage("STARTING EVENT"); c2.waveId++; CycleEventHandler.getSingleton().addEvent(c2, new CycleEvent() { @Override public void execute(CycleEventContainer c) { if (c2 != null) { Server.zombieCaves.spawnNextWave(c2); } c.stop(); }
out of the code provided, which is line 2315?
Code:private void killedZombies(int i) { final Client c2 = (Client)Server.playerHandler.players[npcs[i].spawnedBy]; if (c2 == null) return; c2.zombiesKilled++; System.out.println("To kill: " + c2.zombiesToKill + " killed: " + c2.zombiesKilled); if (c2.zombiesKilled == c2.zombiesToKill) { //c2.sendMessage("STARTING EVENT"); c2.waveId++; CycleEventHandler.getSingleton().addEvent(c2, new CycleEvent() { @Override public void execute(CycleEventContainer c) { if (c2 != null) { Server.zombieCaves.spawnNextWave(c2); } c.stop(); }
zombiesKilled is a primitive datatype, which can never be null (if you don't consider an array to be primitive).
Therefore, c2 is the only object able to be the null.
SGPK's answer is the answer closest to the truth. He/she recognised the c2 variable as the source of the NullPointerException.
But rather than throwing in his 'if(c2 == null) return;", I'd look more into why it is null.
If "c2" is null then "Server.playerHandler.players[npcs[i].spawnedBy];" is null.
Neither "Server", "Server.playerHandler" or "Server.playerHandler.players" is null.
There is however, a null objects inside the array at index "npcs[i].spawnedBy".
If the rest of your code is correct, I can only assume spawnedBy isn't the correct index.
This is why we utilize try and catch. Will prevent server crashes, and player disconnections
Like this:
Code:private void killedZombies(int i) { final Client c2 = (Client)Server.playerHandler.players[npcs[i].spawnedBy]; try{ c2.zombiesKilled++; System.out.println("To kill: " + c2.zombiesToKill + " killed: " + c2.zombiesKilled); if (c2.zombiesKilled == c2.zombiesToKill) { //c2.sendMessage("STARTING EVENT"); c2.waveId++; CycleEventHandler.getSingleton().addEvent(c2, new CycleEvent() { @Override public void execute(CycleEventContainer c) { if (c2 != null) { Server.zombieCaves.spawnNextWave(c2); } c.stop(); } } } } catch (Exception e) { e.printStackTrace(); } }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |
Tags for this Thread |