Solved Null error when getString from config

Discussion in 'Spigot Plugin Development' started by Hacalios, Jul 18, 2018.

Thread Status:
Not open for further replies.
  1. Error in console
    Code (Text):
    null
    org.bukkit.command.CommandException: Unhandled exception executing command 'htnt' in plugin ThrowTNT-v0.1 v0.0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_171]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_171]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
    Caused by: java.lang.NullPointerException
            at me.hacalios.tntplugin.throwtnt.command.onCommand(command.java:46) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            ... 15 more
    Config.yml
    Code (YAML):
    ##################################################################################
    #                                                                                #
    #                                                                                #
    #                                                                                #
    #                                                                                #
    #                                                                                #
    ##################################################################################

    # Làm gì thì làm đừng động đến dòng này
    config-version
    : 1


    ThrowTNT
    :
      1
    :
        name
    : '&cFirst TNT'
        glow
    : false
        lore
    :
       - 'Kaboommm'
      2
    :
        name
    : '&aSecond TNT'
        glow
    : true
        lore
    :
       - 'bem bememem'
    FastTNT
    :
      1
    :
        name
    : '&cFAST TNT'
        glow
    : false
        lore
    :
       - 'Kaboaaaaaaaommm'
    my code:
    Code (Java):
    else if (args.length == 1) {
                     
                            if (args[0].equalsIgnoreCase("throwtnt")) {
                                sender.sendMessage(ChatColor.YELLOW + "[DEBUG] Give Player TNT");
                                ItemStack item = new ItemStack(Material.TNT);
                                ItemMeta meta = item.getItemMeta();
                                String name = plugin.getConfig().getString("ThrowTNT.1.name");
                                meta.setDisplayName(name);
                                item.setItemMeta(meta);
                                p.getInventory().addItem(item);
                         
                        }

                    }


    Line 46 is [ String name = plugin.getConfig().getString("ThrowTNT.1.name"); ]
     
  2. Have you initialized your plugin instance yet with which you are trying to get the String from the config?
     
    • Agree Agree x 1
  3. i solved my problem forgot create a method for plugin in main class
     
Thread Status:
Not open for further replies.