Solved Why am I getting an NPE

Discussion in 'Plugin Help/Development/Requests' started by ibc2244, Jun 3, 2015.

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

    ibc2244

    So... I'm trying to make global strings for all my classes to use. But I get an NPE starting at line 46 and I'm not sure why.

    Here's my Main class code where all them strings are:
    http://pastebin.com/m1HaCgBz

    And here's the error I'm getting:
    http://pastebin.com/rid0RJHz

    Thanks.

    NOTE: I am a bit new to Java but have learnt a fair bit.
     
  2. Offline

    mine-care

    @ibc2244 you get it because instance is not yet initialized, these Static fields are created before the instance gets any value therefore it is null. Take a look at java static and constant fields.
    Btw why don't you have a separate utility class?
     
  3. Offline

    bwfcwalshy Retired Staff

    Moved to land of Alternates.
     
  4. Offline

    ibc2244

    @mine-care

    So, would I do something like... (This code maybe wrong lel)
    Code:
    public static String string = null;
    In my main class then...
    Code:
    Main.string = "Hello";
    In my other class?

    @mine-care

    What do you mean by a separate utility class?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page