Null Pointer | Vault

Discussion in 'Plugin Development' started by mazentheamazin, Dec 15, 2013.

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

    mazentheamazin

    Hey,

    I was working on a plugin that adds permissions and here is the error:
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'insa
    ne' in plugin FatalityPrisonPlugin v1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    2)
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:543)
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:923)
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :803)
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28)
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47)
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    )
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134)
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    45)
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    43)
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    35)
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :447)
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17)
    Caused by: java.lang.NullPointerException
            at com.mazentheamazin.fatalityproject.BuycraftFix.mvp(BuycraftFix.java:1
    9)
            at com.mazentheamazin.fatalityproject.BuycraftFix.mvpplus(BuycraftFix.ja
    va:31)
            at com.mazentheamazin.fatalityproject.BuycraftFix.Leet(BuycraftFix.java:
    39)
            at com.mazentheamazin.fatalityproject.BuycraftFix.Legend(BuycraftFix.jav
    a:48)
            at com.mazentheamazin.fatalityproject.BuycraftFix.Hero(BuycraftFix.java:
    59)
            at com.mazentheamazin.fatalityproject.BuycraftFix.Fatality(BuycraftFix.j
    ava:68)
            at com.mazentheamazin.fatalityproject.BuycraftFix.FatalityPlus(BuycraftF
    ix.java:76)
            at com.mazentheamazin.fatalityproject.BuycraftFix.Insane(BuycraftFix.jav
    a:84)
            at com.mazentheamazin.fatalityproject.CommandHandler.commandInfo(Command
    Handler.java:41)
            at com.mazentheamazin.fatalityproject.Main.onCommand(Main.java:221)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 13 more
    Here is line 221 on Main:
    Code:java
    1. //221 is handler.commandInfo
    2. Player target = Bukkit.getPlayer(args[0]);
    3. if(target.isOnline()){
    4. handler.commandInfo("insane", target);
    5. }

    Here is line 41 on CommandHandler:
    Code:java
    1. if(group.equalsIgnoreCase("insane")){
    2. BCF.Insane(player, "no");
    3. }

    Here is lines 76-97 on BuycraftFix:
    Code:java
    1. public void FatalityPlus(Player player, String var){
    2. Fatality(player, "yes");
    3. vault.permission.playerAdd(player, "essentials.kits.fatality+");
    4. vault.permission.playerAdd(player, "essentials.warps.fatality+");
    5. if(var.equalsIgnoreCase("no")){
    6. variable("&5&l[&d&lFatality&f&l+&5&l]", "&5&n", 25000000, player);
    7. }
    8. }
    9. public void Insane(Player player, String var) {
    10. FatalityPlus(player, "yes");
    11. vault.permission.playerAdd(player, "essentials.tpa");
    12. vault.permission.playerAdd(player, "essentials.vanish");
    13. vault.permission.playerAdd(player, "essentials.near");
    14. vault.permission.playerAdd(player, "essentials.top");
    15. vault.permission.playerAdd(player, "essentials.broadcast");
    16. vault.permission.playerAdd(player, "essentials.nick");
    17. vault.permission.playerAdd(player, "essentials.nick.color");
    18. vault.permission.playerAdd(player, "essentials.nick.format");
    19. vault.permission.playerAdd(player, "essentials.nick.magic");
    20. if(var.equalsIgnoreCase("no")){
    21. variable("&8&l[&r&k12&l&4&lInsane&r&k12&8&l]", "&5&l", 50000000, player);
    22. }
    23. }


    Any help is appreciated.

    Thanks,
    Mazen
     
  2. Offline

    1Rogue Retired Staff

    Can you provide the full BuycraftFix class?
     
    pope_on_dope likes this.
  3. Offline

    mazentheamazin

  4. Offline

    1Rogue Retired Staff

    Don't extend JavaPlugin in multiple classes. You should be only extending it in the main class, and then getting your vault reference from the main class by passing the instance of the main class to "BuycraftFix".
     
    The_Doctor_123 likes this.
  5. Offline

    The_Doctor_123

    mazentheamazin
    As 1Rogue said, you may not extend JavaPlugin in other than your main class. You cannot have more than one instance of JavaPlugin per plugin.
     
  6. Offline

    mazentheamazin

    1Rogue
    The_Doctor_123
    Once I did that it doesn't load the plugin.. This is the only thing it says in console:
    Code:
    [16:19:42 ERROR]: Could not load 'plugins\FatalityProject.jar' in folder 'plugin
    s'
    EDIT: Updated Main Class:
    http://pastebin.com/1SGyE6UJ
     
  7. Offline

    The_Doctor_123

    mazentheamazin
    Try/catch your onEnable() and print out the stack trace.
     
  8. Offline

    1Rogue Retired Staff

    You should be creating the new class instance in your onEnable, not initializing it in the field declaration. Then you would pass the main plugin instance via a constructor.
     
    mazentheamazin likes this.
  9. Offline

    mazentheamazin

    1Rogue The_Doctor_123
    Now this is the error when I run the command (/mvp) I get this error:
    Code:
    Caused by: java.lang.NullPointerException
            at com.mazentheamazin.fatalityproject.BuycraftFix.mvp(BuycraftFix.java:2
    1)
            at com.mazentheamazin.fatalityproject.CommandHandler.commandInfo(Command
    Handler.java:20)
            at com.mazentheamazin.fatalityproject.Main.onCommand(Main.java:84)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 13 more
     
  10. Offline

    1Rogue Retired Staff


    Can you provide your current BuycraftFix code?
     
  11. Offline

    mazentheamazin

  12. Offline

    1Rogue Retired Staff


    Add debug statements to line 21 in BuycraftFix and see what values that you are utilizing are null.
     
  13. Offline

    mazentheamazin

    1Rogue
    Mind if I ask, but how would I do that?
     
  14. Offline

    mydeblob

    mazentheamazin
    Add statements that log to the console in different parts of the code
     
  15. Offline

    mazentheamazin

    mydeblob
    Using that method it reaches up to this line:
    Code:java
    1. main.permission.playerAdd(player, "essentials.kits.MVP");

    But nothing here is set are null. I have just learned the Vault API so if you know what I am doing wrong please inform me/help me.

    Bump

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

    RawCode

    Never ever do it.

    You can get plugin instance by setting some field to "this"


    obviously you shoud check player for null before invoking any methods on it, if you typed wrong name you will get NPE in your current code.
     
  17. Offline

    mazentheamazin

    RawCode
    I have though:
    Code:java
    1. Player target = Bukkit.getPlayer(args[0]);
    2. if(target.isOnline()){
    3. handler.commandInfo("insane", target);
    4. }else{
    5. player.sendMessage(ChatColor.AQUA + "/insane [Online Player]");
    6. }
    7. }else{
    8. player.sendMessage(ChatColor.AQUA + "/insane [Online Player]");
    9. }

    I made sure target is online.
     
  18. Offline

    RawCode

    learn 2 read please.

    null and online is not same things, dont you think soo?
     
  19. Offline

    mazentheamazin

    RawCode
    So how would I check if player is not null?
     
  20. Offline

    RawCode

    Code:
    Player target = Bukkit.getPlayer(args[0]);
     
    if (target == null)
     
      return 
    calling any method versus null object will throw NPE
     
  21. Offline

    mazentheamazin

    RawCode
    Still comes out with the same error here is the updated code:
    Code:java
    1. Player target = Bukkit.getPlayer(args[0]);
    2. if(target == null){
    3.  
    4. }
    5. if(target.isOnline()){
    6. Bukkit.broadcastMessage("Target Online Check Successful");
    7. handler.commandInfo("mvp", target);
    8. Bukkit.broadcastMessage("commandInfo Succesful");
    9. }else{
    10. player.sendMessage(ChatColor.AQUA + "/mvp [Online Player]");
    11. }
     
  22. Offline

    The_Doctor_123

    mazentheamazin
    You really need to learn Java if you don't realize that this does nothing at all:
    Code:java
    1.  
    2. if(target == null){
    3.  
    4. }
    5.  
     
  23. Offline

    Bammerbom

    mazentheamazin
    change: if(target.isOnline()){
    to: else if(target.isOnline()){
     
  24. Offline

    The_Doctor_123

    Jhtzb
    *Sigh*

    There's always somebody that gives the answer away, making the OP not learn anything..
     
  25. Offline

    mazentheamazin

    The_Doctor_123
    1. What method did you use/you recommend for me to learn java
    and 2. Jhtzb
    Still comes out with the same error.
     
  26. Offline

    The_Doctor_123

  27. Offline

    RawCode

  28. Offline

    The_Doctor_123

    RawCode
    Number one.. where did you find that? All people learn different ways. Most people I know say that they read a book, as well as I did. The guide was a personal recommendation, not fact. I explained as to why I thought the documentation wasn't the best, but that doesn't stop people from disagreeing and making their own decisions, nor should it. Although, you took it a step higher and are saying that I'm flat out wrong?
     
  29. Offline

    mazentheamazin

    The_Doctor_123
    I actually took his recommended option as to reading these 2 books: Java for Dummies and Heads first Java I just bought them and I can't thank you soo much.
     
  30. Offline

    RawCode

    The_Doctor_123 i saying that i strongly disagree with your article and closed it without ever reading after noticed quoted line.

    But you advice people to learn from author of some book and take his opinion as one and only eh?
    I wont note that many books contain outdated data.

    Only way to learn properly is to learn from information source no book can explain JAVA better then hotspot (openjdk) source code, no article will explain craftbukkit better then it's source code.
     
Thread Status:
Not open for further replies.

Share This Page