Hi, I've got a problem with my plugin. Here's a code: Code (Text): public static ItemStack getBlazeFishingRodItemStack(){ String it = Main.getConfiguration().getBlazeFishingRodItem(); Material item = Material.matchMaterial(it); String name = Main.getConfiguration().getBlazeFishingRodName(); List<String> lore = Main.getConfiguration().getBlazeFishingRodLore(); ItemStack is = Utils.createItem(item, 1, name, lore); return is; } problem is with getters: they are getting string while I am sending it (sendMessage) but there are nulls. stacktrace: Code (Text): [14:42:11] [Server thread/ERROR]: Error occurred while enabling hs_Tools v1.0 (Is it up to date?) java.lang.NullPointerException at me.hardstyl3r.tools.Main.getBlazeFishingRodItemStack(Main.java:206) ~[?:?] at me.hardstyl3r.tools.Main.onEnable(Main.java:44) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292) ~[spigot.jar:git-Spigot-8a048fe-106ced0] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-8a048fe-106ced0] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-8a048fe-106ced0] at org.bukkit.craftbukkit.v1_9_R2.CraftServer.loadPlugin(CraftServer.java:362) [spigot.jar:git-Spigot-8a048fe-106ced0] at org.bukkit.craftbukkit.v1_9_R2.CraftServer.enablePlugins(CraftServer.java:322) [spigot.jar:git-Spigot-8a048fe-106ced0] at net.minecraft.server.v1_9_R2.MinecraftServer.t(MinecraftServer.java:416) [spigot.jar:git-Spigot-8a048fe-106ced0] at net.minecraft.server.v1_9_R2.MinecraftServer.l(MinecraftServer.java:381) [spigot.jar:git-Spigot-8a048fe-106ced0] at net.minecraft.server.v1_9_R2.MinecraftServer.a(MinecraftServer.java:336) [spigot.jar:git-Spigot-8a048fe-106ced0] at net.minecraft.server.v1_9_R2.DedicatedServer.init(DedicatedServer.java:268) [spigot.jar:git-Spigot-8a048fe-106ced0] at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:532) [spigot.jar:git-Spigot-8a048fe-106ced0] at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
Obviously there's something wrong. You fucked up somewhere. Try isolating where the issue is. Print getConfiguration != null Print getBlazeFishingRodCrafting != null
Code (Java): java.lang.NullPointerException at me.hardstyl3r.tools.Main.getBlazeFishingRodItemStack(Main.java:206) ~[?:?] at me.hardstyl3r.tools.Main.onEnable(Main.java:44) ~[?:?] check the error again.
Code (Text): public static ItemStack getBlazeFishingRodItemStack(){ String it = Main.getConfiguration().getBlazeFishingRodItem(); Material item = Material.matchMaterial(it); String name = Main.getConfiguration().getBlazeFishingRodName(); List<String> lore = Main.getConfiguration().getBlazeFishingRodLore(); ItemStack is = Utils.createItem(item, 1, name, lore); return is; } and the Utils.createItem: Code (Text): public static ItemStack createItem(Material dc, int typeID, String name, List<String> description){ ItemStack i = new ItemStack(dc, 1, (byte)typeID); ItemMeta im = i.getItemMeta(); im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); ArrayList<String> lore = new ArrayList<>(); for (String line : description) { lore.add(ChatColor.translateAlternateColorCodes('&', line)); } im.setLore(lore); i.setItemMeta(im); return i; }
Ok, what is line 206 of the "Main" class? Also make sure your configs are registered before using the methods, as you use this method in onEnable.
have you prepare the File and FileConfiguration of your custom yml in onEnable() ? and how do you access Main class to the other one ?
yes, configs are working, but only there they aren't. it's 206 line in my Main.class. Code (Text): Material item = Material.matchMaterial(it);
Code (Text): public String getBlazeFishingRodItem(){ return blazefishingroditem; } and Code (Text): this.blazefishingroditem = this.file.getString("blazefishingrod.item"); file = config it just returns "FISHING_ROD"
well I'm confused is the .file is really config ? just look at this 2 Code (Java): File file; // did you used this one ? FileConfiguration file; // or this one?
in Configuration.class: Code (Text): public Configuration(FileConfiguration file) { this.file = file; (it's private FileConfiguration file;) this.loadConfiguration(); } and it's loaded by: Code (Text): public void loadConfiguration() { this.saveDefaultConfig(); configuration = new Configuration(this.getConfig()); }
use the FileConfiguration when getting string on a file something like this Code (Java): FileConfiguration config = YamlConfiguration.loadConfiguration(file); // then get the string with it config.getString(path);