Solved Error Creating Instance of A Class

Discussion in 'Plugin Development' started by JungleSociety, Jul 1, 2014.

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

    JungleSociety

    Hello, I am receiving an error on one of my projects when the server starts up. If anyone was wondering I am using @xTrollxDudex's minigame tutorial, however I believe it has to do with something I'm doing wrong with the plugin itself not the minigame outline. So anyways I get a startup log, that will be below, and I see errors on lines that appear to be getting the instance of the ArenaManager class. I'm fairly new to java, but from what I've read, I think that I'm creating the instance of the class at least somewhat correct. So here is the code and the error, Thanks:

    TNTWars class: http://pastebin.com/0dBu8L2A

    ArenaManager class: http://pastebin.com/7zfdSXHP

    Error: http://pastebin.com/ruGfgaS3

    Sorry I had to use pastebin because the post wouldn't allow over 30,000 characters.

    Please let me know if you need anything else to help me solve this, like other classes or full logs or anything. I'm assuming there is a very simple answer to this, that my knowledge is not bringing up right now. Thanks.
     
  2. Offline

    AoH_Ruthless

    JungleSociety
    I'm not going to spoonfeed you the solution, frankly because you won't learn and because I don't want to read up to 30,000 characters ..

    You need to learn to read stacktraces. The stacktrace clearly points to line 39 of TNTWars class. This is improper initialization because you are initializing the instance outside of any method. This is declared even before your onEnable(). How can you enable an ArenaManager class that relies on the main class before the main class is even enabled? It would be like trying to stand up without legs (dark, but first thing I could think of). It just does not make sense.

    Also, your comment about being "fairly new to Java" means you should stop right now and take the time to learn Java. Seriously, it will improve your life ten fold.
     
  3. Offline

    JungleSociety

    AoH_Ruthless
    Thank you for your time and response, I'll be messing around with what you said to see if I can get the solution.

    Also by "fairly new to Java", I mean that I've been taking a computer science and programming class at a local school, that mainly works with Java. My goal isn't to just make Bukkit plugins, but to understand the concept behind programming, and I believe that one of the best ways to do this, is to create something that you would enjoy. Recently what we have been coding in my class for assignments is not necessarily considered "fun" to me. But Bukkit is, and I can see my work come to life in one of my favorite games. This inspires me to continue and learn more and get into it even deeper. Anyways thanks for your response :D
     
  4. Offline

    Heirteir

    JungleSociety
    change
    Code:java
    1. SettingsManager settings = SettingsManager.getInstance();

    to
    Code:java
    1. SettingsManager settings;
    2.  
    3. public void onEnable(){
    4. settings = SettingsManager.getInstance();
    5. }


    You might be doing this in other places but you can't create instances before your plugin is enabled...
     
    JungleSociety likes this.
  5. Offline

    JungleSociety

    Heirteir
    Thank you very much for your response. You made it very clear what the problem was. Thank you.
     
    Heirteir likes this.
  6. Offline

    ReggieMOL

Thread Status:
Not open for further replies.

Share This Page