[Solved] java.lang.IllegalArgumentException: Plugin already initialized. What’s going on?


The stacktrace clearly tells where is the problem. What is a stack trace, and how can I use it to debug my application errors?
The error:

java.lang.IllegalArgumentException: Plugin already initialized!
...
Caused by: java.lang.IllegalStateException: Initial initialization
...
at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]

Your code:

@Override
public void onEnable() {
    getServer().getPluginManager().registerEvents(new Main(), this);
} //<-- 19th line

And the problem is when you register your event you are creating a new instance of your Main class. So replace new Main()

getServer().getPluginManager().registerEvents(new Main(), this);

with this

getServer().getPluginManager().registerEvents(this, this);

solved java.lang.IllegalArgumentException: Plugin already initialized. What’s going on?