Solved null error when creating team

Discussion in 'Plugin Development' started by RAFA_GATO_FOFO, Apr 15, 2014.

Thread Status:
Not open for further replies.
  1. Hey guys, I'm getting this error:
    Code:
    [14:22:07 INFO]: RAFA_GATO_FOFO issued server command: /team
    [14:22:09 INFO]: RAFA_GATO_FOFO issued server command: /team new
    [14:22:11 INFO]: RAFA_GATO_FOFO issued server command: /team new soup
    [14:22:11 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'team
    ' in plugin UHCraft v0.0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:17
    5) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:952) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader
    .java:98) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[craftb
    ukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at me.rafagatofofo.UHCraft.TClass.<init>(TClass.java:14) ~[?:?]
            at me.rafagatofofo.UHCraft.Main.CreateTeam(Main.java:17) ~[?:?]
            at me.rafagatofofo.UHCraft.Main.onCommand(Main.java:69) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 13 more
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader
    .java:101) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[craftb
    ukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at me.rafagatofofo.UHCraft.Main.<init>(Main.java:14) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     ~[?:1.7.0_51]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     ~[?:1.7.0_51]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce) ~[?:1.7.0_51]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_5
    1]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_51]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
    a:52) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:133) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:313) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:236) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va:350) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(CraftServer.java:77
    1) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.Bukkit.reload(Bukkit.java:279) ~[craftbukkit.jar:git-Bukki
    t-1.7.2-R0.3-b3020jnks]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 13 more
    >CreateTeam(args[1])
    [14:23:11 INFO]: Unknown command. Type "help" for help.
    >
    When using the command "/team new"
    When I use "/team" it works, but "/team new" and "/team new name" bugs out
    Code:java
    1. if(label.equalsIgnoreCase("team")){
    2. switch(args.length){
    3. case 0:
    4. player.sendMessage(ChatColor.DARK_RED + "Invalid Arguments!");
    5. break;
    6. case 1:
    7. switch(args[0].toLowerCase().toString()){
    8. case "new":
    9. player.sendMessage(ChatColor.DARK_RED + "Invalid Arguments!");
    10. break;
    11. case "invite":
    12. player.sendMessage(ChatColor.DARK_RED + "Invalid Arguments!");
    13. break;
    14. case "accept":
    15. player.sendMessage("ACCEPT");
    16. break;
    17. case "deny":
    18. player.sendMessage("DENY");
    19. break;
    20. }
    21. break;
    22. case 2:
    23. if(args[0].toLowerCase().toString().equals("new")){
    24. CreateTeam(args[1]);
    25. player.sendMessage("You've created and joined Team " + args[1]);
    26. }else if(args[0].toLowerCase().toString().equals("invite")){
    27.  
    28. }
    29. break;
    30. }
    31. }


    CreateTeam is a method in my TClass.java
    I got it on Main as:
    Code:java
    1. public void CreateTeam(String Teamname){
    2. new TClass().createTeam(Teamname);
    3. }


    TClass.java has this:
    Code:java
    1. public void createTeam(String Teamname){
    2. List<Player> emptyteam = new ArrayList<Player>();
    3. teams.put(Teamname, emptyteam);
    4. }
     
  2. Offline

    Bionicrm

    Could you explain your problem a little better? Also, use indentation in your code; it's very difficult to read as it is. :)
     
  3. Offline

    Aengo

    Doesn't look like a nullpointer to me..
     
  4. Bionicrm
    Well I get the error in the console when I perform either "/team new" or "/team new name". The method i'm using (createTeam) is imported from another class called TClass. TClass has the public void createTeam as displayed in the last code...

    Aengo
    But the error displayed is an NPE, that's what's bugging me
     
  5. Offline

    skyrimfan1

    I don't see a NPE, rather I see an IllegalStateException, IllegalArgumentException, and a CommandException. The stacktrace is a combination of all three.
     
  6. skyrimfan1
    Oh I thought the null at the start meant NullPointerException. But what's actually wrong with the code I wrote? Or is it something else that I didn't post yet?
     
  7. Offline

    Aengo

    Well, we need to see all of your code, else we can't tell you what is wrong.
     
  8. Aengo
    Why would you need to see all of the code if the error is in the snippets I posted?
    The code in the first thread doesn't use anything else other than what is already there.

    Bump, if someone could help me with this, I honestly have no idea what's wrong and I'm kinda stuck.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    BillyGalbreath

    What is this???

    Code:java
    1.  
    2. public void CreateTeam(String Teamname){
    3. new TClass().createTeam(Teamname);
    4. }
    5.  


    You are trying to create your class AGAIN. Your class already exists, and is already loaded..

    Try this instead if you are accessing it in a static way:

    Code:java
    1.  
    2. public void CreateTeam(String Teamname){
    3. TClass.createTeam(Teamname);
    4. }
    5.  


    Or like this is you have a reference to the instance:

    Code:java
    1.  
    2. public void CreateTeam(String Teamname){
    3. instance.createTeam(Teamname);
    4. }
    5.  
     
  10. RAFA_GATO_FOFO Just because we can see the line that has the error, doesn't mean we know for sure what's wrong. :)

    The post above by BillyGalbreath is probably right, based on simple logic. But there's always the chance that TClass isn't your main class, which would mean that the above is not why you're getting the error.

    Chances are, though, that it is your main class and that's why you're getting the error.
     
  11. AdamQpzm
    My main class is named Main, TClass isn't the main class, I specified that in the first post.

    BillyGalbreath
    I'll take a look at that in the morning Billy, the code is on my laptop, I was just here checking for news. I'll reply if something comes up!
     
  12. RAFA_GATO_FOFO In that case, BillyGalbreath's suggestion won't solve your errors - it would only work if TClass was your plugin's main class. Which means that we're going to need to see the full code because something tries to enable your plugin twice. That usually only happens in the plugin's own code, or when there are name clashes, or when there's more than one copy of the plugin in the folder. :p

    Also, just noticed, why do you use toString() on String objects? Like args[1].toLowerCase().toString()? Just seems unnecessary.
     
  13. Offline

    BillyGalbreath

    If TClass is not the main class I'm willing to bet you have it extend JavaPlugin (which you shouldnt). Or your TClass constructor is reloading your main class again probably by using similar lines to new Main().something() like you did in the above examples with TClass.

    Study more into how classes and instances work, if thats the case.
     
  14. It's extended as a JavaPlugin, yeah that fixed it. Thanks BillyGalbreath
     
Thread Status:
Not open for further replies.

Share This Page