Solved new ItemStack() returns null???

Discussion in 'Plugin Help/Development/Requests' started by Awesomebanana2002, Jul 30, 2015.

Thread Status:
Not open for further replies.
  1. Hi there, I've beed trying to fix this for about 4 hours now, and I cant get it to work. My method:
        private void parseIcon() {
            String format = Kits.get().getString( + ".icon");
            String name = Kits.get().getString( + ".display-name");
            int id = 1;
            short damage = 0;
            if(format.contains(":")) {
                String[] parts = format.split(":");
                id = Integer.parseInt(parts[0]);
                damage = (short) Integer.parseInt(parts[1]);
                id = Integer.parseInt(format);
            icon = new ItemStack(id, 1, damage);
            if(icon == null)
                Bukkit.getLogger().warning("icon == NULL");
            ItemMeta im = icon.getItemMeta();
    When you don't give the icon a damage, (without :1), it runs fine, but when you do, the variable icon is null..
    Does someone know how to fix this. If so, please help me out :)
  2. Offline


    I think 0 might mean its broken, so try with 1, or no number at all

    - just a guess, havent done bukkit programming in a while now.
  3. @tommyhoogstra Hmm.. I dont think thats the problem. It only sets the damage to 0 when it can't find ":" in the format.

    EDIT: Tried it.. Still won't work
  4. @Awesomebanana2002 there is no way that a constructor returns null. this is not possible in java. the only way would be that an exception is thrown what would be shown in the console. Is there any? Btw why aren't you saving the enum.toString() instead of the id? this way you could get the material by enum.valueOf(String)
  5. @Shmobi I wont save it, so the users that are using the plugin can set their own kits, and I might try enum.valueOf();
    And yes, I get an error. It happens when I set the display name to the ItemMeta. I did a check if that string was null, and it wasn't. It only gives the error when the format contains ":". Otherwise it sets the display name fine...

    Heres my error:
    [13:04:06 WARN]: java.lang.NullPointerException
    [13:04:06 WARN]:        at com.TheWGB.SG.kits.Kit.parseIcon(
    [13:04:06 WARN]:        at com.TheWGB.SG.kits.Kit.<init>(
    [13:04:06 WARN]:        at com.TheWGB.SG.kits.KitManager.loadKits(KitManager.jav
    [13:04:06 WARN]:        at com.TheWGB.SG.Main.onEnable(
    [13:04:06 WARN]:        at
    [13:04:06 WARN]:        at
    [13:04:06 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    [13:04:06 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    [13:04:06 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    [13:04:06 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    [13:04:06 WARN]:        at org.bukkit.Bukkit.reload(
    [13:04:06 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    [13:04:06 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    [13:04:06 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    [13:04:06 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    [13:04:06 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    [13:04:06 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    [13:04:06 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    [13:04:06 WARN]:        at
    [13:04:06 WARN]:        at Source)
    [13:04:06 WARN]: [SurvivalGames] Could not load kit apple-master correctly! java
    EDIT: Just checked.. Nothing is null in the method!!! And it gives me a NullPointerException.. What the...
    Last edited: Jul 30, 2015
  6. Offline


    @Awesomebanana2002, did you consider that Bukkit is responsible for the null field?
    If a type does not have a data field, giving it one results in a nonexistant itemstack, causing bukkit to throw a null pointer.
  7. Fixed... Apparantly you cant use a ':' in the config.. This is what I used before: 'icon: 322:1' and now im using 'icon: 322 1'.... I just want to rage right now.
  8. Offline


    you can use colins in the configs, just make sure they are quoted values
    ...icon is your pathway/key '322:1' is the value

    icon: '322:1' works
Thread Status:
Not open for further replies.

Share This Page