Thread: PvN - NullPointerException

Results 1 to 3 of 3
  1. #1 PvN - NullPointerException 
    Registered Member
    Deadly Uzi's Avatar
    Join Date
    Jul 2008
    Posts
    994
    Thanks given
    177
    Thanks received
    87
    Rep Power
    362
    Hello!

    I have one problem that annoys the crap out of me and I can't solve it, I think I am missing something really obivous too!

    Ok, I made a class(CombatCaller) that controls the packet(s) that have to do with combat.

    So I got the packet 72, that is Attack NPC. Here is the code for it -

    Code:
    	static void handleAttackNPC(Packet p, Player player, ActionSender sender) {
    		int victim = p.readShortA();
    		
    		if (NPCManager.isValid(victim)) {
    			Combat.attackNPC(victim, player);
    		}
    		
    	}
    The attackNPC packet ID is 72, which is what it is supposed to be.

    Here is the attackNPC method in my CombatController,

    Code:
    	public void attackNPC(int victim, Player player) { // Handles PVN.
    
    		if (!NPCManager.isValid(victim)) {
    			sender.sendMessage("You cannot attack this NPC.");
    			return;
    		}
    
    		NPC n = NPCManager.getNPC(victim);
    
    		player.setAttackingNPC(n);
    
    		sender.sendMessage("You attack a NPC with an ID of: " + victim);
    		player.setEntityFace(victim);
    
    		if (n.isMoveable())
    			n.setMoveable(false);
    	}
    I do not see any problems with the code, however when I attack an NPC, I get a NullPointerException. The FIRST line that the error comes up is the line - Combat.attackNPC(victim, player);.

    Please help me! I have no idea and this is delaying me from continuing with my combat!

    Thanks a lot in advance!
    -Deadly Uzi
    Attempting to develop a multi-revision library. See it on GitHub.
    Reply With Quote  
     

  2. #2  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Under

    NPC n = NPCManager.getNPC(victim);
    You need to check if the victim is a null so,

    if(n == null)
    return;
    Reply With Quote  
     

  3. #3  
    Registered Member
    Deadly Uzi's Avatar
    Join Date
    Jul 2008
    Posts
    994
    Thanks given
    177
    Thanks received
    87
    Rep Power
    362
    It still gives the NullPointer... I have no idea!!! I'm going crazy over this!
    Attempting to develop a multi-revision library. See it on GitHub.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •