[SOLVED] Null Pointer Exception

Discussion in 'Spigot Plugin Development' started by GODofCRAFTERS, Jun 14, 2015.

  1. Hey guys. I'm sure I'm just being stupid and missing something super easy but I'd appreciate if you guys could point out the error as I've gone through the code a lot and don't understand why I'm getting a null pointer exception.

    Here's the code:
    Code (Text):
            Channel global = new Channel("global", "G", "&e");
            Channel donator = new Channel("donator", "D", "&2");
            Channel staff = new Channel("staff", "S", "&c");
            channels.add(global);
            channels.add(donator);
            channels.add(staff);
    I'm getting the NullPointerException at line no. 4 (with reference to the above lines of code). I understand that the variable "global" of type "Channel" is pointing to a null. But I don't understand why.

    "channels" is of type "Set". [Set<Channel> channels;]
     
  2. You say you have declared channels as type Set<Channel>, and that's fine, but did you create the actual set? For example, channels = new HashSet<Channel>();
     
  3. Could you please show where you created the Set? As @St3venAU said, it might not be initiated.
     
  4. @St3venAU
    You're my saviour <3
    I knew it was something stupid.
    Thanks so much!!!!