Solved Null Pointer Exception Error in ArrayList

Discussion in 'Plugin Development' started by VinexAx789, May 16, 2016.

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

    VinexAx789

    Problem solved, I just didn't initialize these in my constructor
    public MainMenu kitClass = new MainMenu(plugin);
    public EndGame endGame = new EndGame(plugin);
     
    Last edited: May 16, 2016
  2. Offline

    Gonmarte

    Error 1:
    LINE 45: winners = plugin.attackersPlayerWins;

    - the variable plugin can be null.
    - attackersPlayerWins can be null also.
    - So, winners would be null.
    Error 2:
    - Caused by the NPE of the first error.

    You probably wanna show us how do you setup the plugin variable and the list attackersPlayersWins.
     
  3. Offline

    VinexAx789

    @Gonmarte Alright,

    I use the Plugin variable like this:

    Code:
    public DTP plugin;
       
    public DeathEvents(DTP plugin) {
            this.endGame = new EndGame(plugin);
            this.kitClass = new MainMenu(plugin);
            this.plugin = plugin;
        }

    Then the attackerPlayerWins like this
    Code:
    attackerPlayerWins.add(p.getName());
    Sorry that doesn't seem like at all what you wanted.
     
  4. Offline

    I Al Istannen

    @VinexAx789
    If the error is near where you said it is, the first thing that can throw this is this (I think):
    The line @Gonmarte said won't to anything It does if plugin is null, as you can assign null values as often as you want. You need to make sure, that plugin is not null and that attackersPlayerWins is not null. Just add a System.out.println(plugin == null); and under that a System.out.prinln(plugin.attackerPlayerWins == null);. Then paste them right above the Switch statement in the endGame method and report the output.

    EDIT: Sorry gonmarte, read that wrong. The error is most likely plugin being null!
    EDIT2: That makes no sense too, as the statement before (changing the game state) executes just fine :confused:
     
    VinexAx789 likes this.
  5. Offline

    VinexAx789

    @I Al Istannen I fixed it I was being dumb xD

    I didn't Initialize these in my constructor
    public MainMenu kitClass = new MainMenu(plugin);
    public EndGame endGame = new EndGame(plugin);
     
  6. Offline

    Gonmarte

    No problem ;)
     
    VinexAx789 likes this.
Thread Status:
Not open for further replies.

Share This Page