Constructor to main class may not have been initialized

Discussion in 'Plugin Development' started by Incomprehendable, Apr 21, 2014.

Thread Status:
Not open for further replies.
  1. [​IMG]
    My constructor is saying that my instance may not have been initialized. I used the same (exact) code in some other listeners and it didn't return an error so I'm pretty confused with this one.
     
  2. Offline

    beeselmane

    pl is final, meaning that the field should not be modified. Take off the final modifier, and it should be fine (private SDJ pl;)
     
  3. Offline

    RawCode


  4. The stacktrace is just an NPE at the dofall List<String> object.
     
  5. Offline

    beeselmane

    RawCode
    care to explain? Pretty sure it's because it's an instance variable, and the other variables would be initialized using the variable from the instance, which, at the time, is null, because it would do that before the constructor has actually been called

    Also, to fix this move these initializations of the variables that use pl to inside the constructor, and set them to null (or don't initialize them) in the field's declaration
     
  6. Offline

    RawCode

    beeselmane
    read javaspecs about what final keyword means and how it works.
    provided implementation is valid and maynot cause issues by itself.

    Incomprehendable
    i dont ask about what your opinion about stacktrace, i ask stacktrace, if you want to recieve some help - provide it
     
  7. I didn't give you my opinion about the stacktrace. I told you what it was.
    Here's the stacktrace. Line 31 is the dofall line.
     
  8. Offline

    YoshiGenius

    Initialize the variables inside the constructor instead of outside it. That will fix your issues.
     
    beeselmane likes this.
  9. Offline

    RawCode

    protip that will teach you to find and fix issues likes this

    someconstructor ()
    {
    System.out.println("INSIDE CONSTRUCTOR");
    }
    somefield Void az = System.out.println("Inside field section");

    fix pseudocode above and invoke it, you will get answer.
     
  10. Alright, but can you explain why it doesn't work on my OnPlayerToggleFlight class but works fine on my other listeners? I'm just curious as to why because this isn't an issue that I've come across before, and I've been developing for a bit now. I know that it means that there's a way for the localized variable to return as null but how?
     
Thread Status:
Not open for further replies.

Share This Page