Big problem with array lists

Discussion in 'Spigot Plugin Development' started by david9090, Aug 15, 2018.

  1. Hello everybody, i'm posting for the first time here to maybe solve a very disturbing problem.

    I simply can't use an array list

    I must say that i'm a beginner in spigot.

    First time i tried to use one, i created it in my main class and created an instance to permit ther classes interact with my list.

    That was a command who were stocking the first argument (0) , checked if that arg were an online player , and if it was, stocking him into my player array list . Player in that list could use another command.

    But, it didn't work. When i was trying my first command, i had an internal error, same for the second one

    So i tried to create a new array list that get a player when he join (player join event) and send a message to the player that just connected to tell him the size of the array list. But, AGAIN, i had no error in eclipse, everything seemed to be okay, and when i connected; i received nothing and seen an internal error.

    Here are some screen shots of my main class and the listener one.

    Attached Files:

    • 1.PNG
      File size:
      17.9 KB
    • 2.PNG
      File size:
      9.7 KB
    • 3.PNG
      File size:
      25.7 KB
  2. Choco


    With regards to the third attached image, you've not initialized your "main" field yet you use it in your method resulting in a NullPointerException. You should initialize that variable through the constructor. Though in the future, please provide your error as well as it's more useful than you may think. Additionally, code snippets (wrapping your code in [CODE=java][/CODE] tags in the post) makes things a lot easier to read for us.

    Thread moved to Spigot Plugin Development
  3. Basically what 2008Choco said, you have your MonPlugin object but it is not referencing any instance, therefore, resulting in a nulled object
  4. Here is my internal error:

    Attached Files:

    • 4.PNG
      File size:
      62.9 KB
  5. add main= this;
    in the onenable method
    u forgot to initialize the main
  6. still not working , look

    Attached Files:

    • 5.PNG
      File size:
      17.6 KB
  7. Look on line 48 on your code, which line of code is that?
  8. line 48 of which class?
  9. I guess your classes need that instance. You need to pass it through their constructor and assign it to the field in that class. (In fact, one of the method in a screenshot use it, but i guess you never initialize it). BTW @2008Choco already said that, i will suggest you read, learn and google not hope someone will spoonfeed solving your problems magically.
  10. How can i initialize it by the constructor?

    I would suggest you use google sometimes. It does really work (Just searched constructor java into google).