NullPointer...

Discussion in 'Plugin Development' started by Kiwanga, Oct 13, 2015.

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

    mine-care

    http://bukkit.org/threads/how-to-re...ubleshoot-your-own-plugins-by-yourself.32457/

    Also let me note a few things:
    Code:
    public static HashMap<Player, Player> teameinladung = new HashMap<>();     public static HashMap<Player, Player> teamannahme = new HashMap<>();
    Dont abuse static
    Encapsulate
    dont store player long term since it is know to cause ram leaks when not hanled properly.

    And also, follow naming conventions
     
    Zombie_Striker likes this.
  2. Offline

    caseif

    To expand on this a bit, it's also a terrible idea to use mutable objects as HashMap keys, the reason being that if the object is mutated in such a way that the hashcode changes, it will no longer match the code stored by the map and therefore will no longer be able to recall the associated value. Same logic goes for Sets, albeit in a slightly less breaking way.
     
  3. Offline

    DoggyCode™

    But if he wants to access the map from a different class, how would he possibly do it without public static?
     
  4. Offline

    Tecno_Wizard

    @DoggyCode™, uhh, one of the most basic principles of Java. OOP. If you don't know that you have a serious issue.
     
  5. Offline

    DoggyCode™

    I kind of skipped that part..
     
  6. Offline

    Tecno_Wizard

    @DoggyCode™, for your own sake, learn to understand what is going on here.

    Code:
    public class Test {
    public static void main(String args) {
      Example example = new Example("An Object", 1);
      example.printID();
    }
    }
    public class Example {
      private String name;
      private int id;
      public Example(String name, int id) {
         this.name = name;
         this.id = id;
      }
      public void printID() {
        System.out.println(this.id);
      }
    }
    If there's a typo, I did this on my phone.


    For OP, use the thread @mine-care linked.
     
  7. Offline

    DoggyCode™

    Thanks..
     
  8. Offline

    caseif

    In fairness, the main plugin class is effectively a singleton, so using a static has more or less the same effect as using an instance variable in this particular case.
     
    DoggyCode™ likes this.
  9. Offline

    Tecno_Wizard

    @caseif these were not in the plugin class.
     
  10. Offline

    caseif

    Ah. my bad then.
     
  11. Offline

    Tecno_Wizard

    @caseif, not a problem, but yes, I'd understand the sense of it is if was the plugin main class.
     
  12. Offline

    mythbusterma

    @caseif @Tecno_Wizard

    Even then, the concept of "encapsulation" doesn't just not apply because the class could reasonably be considered a singleton. All that means is that you can have a static method that gets the instance of that Object.

    You still should have getter and setter methods regardless.
     
  13. Offline

    Tecno_Wizard

    @mythbusterma, agreed, but I really didn't want to fight it at that moment. The stress that comes with college applications... I don't need any more.
     
Thread Status:
Not open for further replies.

Share This Page