Error with constructor?

Discussion in 'Plugin Development' started by WesJD, Nov 22, 2014.

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

    WesJD

    I'm not sure what's the error here, though I'm getting spammed in my console with object/constructor errors. In my mind I don't see what's wrong..?

    Stacktrace(Only put one.. showing them being spammed is useless):

    Code:
    at me.Wes.VillageSnipe.GameManager.<init>(GameManager.java:25) ~[?:?]
    at me.Wes.VillageSnipe.Scoreboards.<init>(Scoreboards.java:23) ~[?:?]
    Line 25 of GameManager:

    Code:java
    1. Scoreboards Scoreboards = new Scoreboards();


    Line 23 of Scoreboards:

    Code:java
    1. GameManager GameManager = new GameManager();


    Thanks in advance.
     
  2. Offline

    mrCookieSlime

    WesJD
    I think you created a loop.
    Whenever you create an instance of GameManager it will create an instance of Scoreboards which creates an instance of GameManager which creates an Instance of Scoreboards etc.

    Maybe do Scoreboards(GameManager manager) instead.
     
  3. Offline

    WesJD

    mrCookieSlime
    As in...
    Code:java
    1. Scoreboards Scoreboards = new Scoreboards(GameManager GameManager);

    ?
    Or am I over thinking it?
     
  4. Offline

    mrCookieSlime

    WesJD
    ... I mean that you better want to add a GameManager argument to your constructor so you use an existing instance rather than creating a new one.
     
  5. Offline

    Skionz

    He means put your GameManager instance as the parameter for the constructor.
     
    teej107 likes this.
  6. Offline

    WesJD

    Skionz
    Could you give me an example? I'm not quite getting it..
     
  7. Offline

    Skionz


    Code:
    Scoreboards scoreboard = new Scoreboards(yourGameManagerInstance);
    Personally I have never used scoreboards before and I am just following what mrCookieSlime has said.
     
  8. Offline

    WesJD

    Skionz
    Though what would my instance be? Plugin...?
     
  9. Offline

    Skionz

    Your instance of the GameManager class
     
  10. Offline

    teej107

    What ever you want it to be. It is your code and not mine.
     
    Skionz likes this.
  11. Offline

    WesJD

    teej107 Skionz
    Then basically I'm doing what is above. Just gives me an error in Eclipse? This is what I have now:

    Code:java
    1. GameManager manager;
    2. Scoreboards Scoreboards = new Scoreboards(manager);
     
  12. Offline

    Skionz

    WesJD First off you probably shouldn't capitalize the first letter of variable. Second of all you will probably have to initialize manager. Third you need to tell us what the error says.

    EDIT: And what is the "Scoreboards" class? Is it built in because I couldn't find it on the javadocs.
     
  13. Offline

    WesJD

    Skionz
    The Scoreboards class is a class in my package.
     
  14. Offline

    teej107

    WesJD Let me take a guess at your error. It's because the constructor of Scoreboards doesn't accept GameManager in its constructor parameters. Is this right?
     
    Skionz likes this.
  15. Offline

    WesJD

  16. Offline

    teej107

    WesJD So you got it fixed then?
     
  17. Offline

    Skionz

    Did you make this class? If so shouldn't you know how to use it? If not give us a link to whatever your using.
     
  18. Offline

    WesJD

    teej107
    Nope.

    Skionz
    I did create it. It's a class creating scoreboards. I'm in need to access it due to methods I need.
     
  19. Offline

    teej107

    WesJD Is it a class that you made?
     
  20. Offline

    mythbusterma

    WesJD

    Still doesn't mean that it should be capitalized.

    What's the issue you have?
     
  21. Offline

    WesJD

    teej107
    Yes, I'm editing a variable within the class to update a player's score.
     
  22. Offline

    Dragonphase


    For future reference, please provide the full stacktrace.
     
  23. Offline

    teej107

    WesJD Well I think you gotten your answer on how to fix the error.
     
  24. Offline

    WesJD

    mythbusterma
    When creating the instances they create each other, making a loop that breaks the plugin.
     
  25. Offline

    mythbusterma

    WesJD

    So don't do that.
     
  26. Offline

    teej107

    WesJD I thought you fixed that right? And now you are having problems with sending an Object instance through a parameter.
     
  27. Offline

    WesJD

  28. Offline

    mythbusterma

    WesJD

    I'd prefer you didn't either. I meant don't create cyclical constructors.
     
  29. Offline

    WesJD

    mythbusterma
    Both classes need to access each other. Am I just being dumb right now? lol
     
  30. Offline

    teej107

    WesJD Not to sound harsh but yes!
     
Thread Status:
Not open for further replies.

Share This Page