NullPointerException

Discussion in 'Plugin Development' started by Ethan, Jul 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Ethan

    So in my code to determine if when 2 players hit each other they don't take damage

    Code:java
    1. public class PartnershipListener implements Listener {
    2. public static Partnership plugin;
    3.  
    4. public void onEntityDamage(EntityDamageByEntityEvent event){
    5. Entity damager = event.getDamager();
    6. if(damager instanceof Player){
    7. Entity damagee = event.getEntity();
    8. if(damagee instanceof Player){
    9. Player p = (Player)damagee;
    10. Player pp = (Player)damager;
    11. if(plugin.getConfig().getString(p.getName(), ".married").equalsIgnoreCase(pp.getName())){
    12. event.setCancelled(true);
    13. }else{
    14. event.setCancelled(false);
    15. }
    16. }
    17. }
    18. }
    19. }


    I keep getting a NullPointerException, which I can't figure out why, since I check to make sure if the damager/damagee is a player or not before converting the entity to a player and if the player name is not in the config shouldn't it just come up as false?

    Code:
    Caused by: java.lang.NullPointerException
            at me.wam19.ProtectionPlugin.Listeners.ProtectionPluginListener.onPlayer
    Interact(ProtectionPluginListener.java:45)
     
  2. Offline

    Woobie

    Ethan
    Look at the error, silly. It throws the NPE on "onPlayerInteract" method, not the method above.

    By the way, you forgot @EventHandler ;)

    EDIT: Now that I look at it, I don't think it's even the same plugin.
     
  3. Offline

    Ethan

    Wow, guess I need to take a break q.q
     
  4. Offline

    Woobie

    Or code like a madman, until you know everything, and forget nothing :)
     
Thread Status:
Not open for further replies.

Share This Page