Solved NBTTagCompound error

Discussion in 'Plugin Development' started by InfamousSheep, Oct 17, 2014.

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

    InfamousSheep

    Hello people, I'm receiving a null pointer exception when trying to get the NBTTagCompound from a CraftItemStack.
    Here's the error:
    Code:
    Caused by: java.lang.NullPointerException
            at com.marcus.test.objects.Books.getItemStack(Books.ja
    va:40) ~[?:?]
    
    Here's the method:
    Code:
    public ItemStack getItemStack() {
    ItemStack itemStack = new ItemStack(Material.WRITTEN_BOOK);
    CraftItemStack book = getCraftVersion(itemStack);
    net.minecraft.server.v1_7_R4.ItemStack nmsCopy = CraftItemStack.asNMSCopy(book);
    NBTTagCompound tags = nmsCopy.getTag();
     
    NBTTagList nPages = new NBTTagList();
    int i = 0;
    for (Page page: pages) {
    String[] derp = page.getPage();
    nPages.add(new NBTTagString(derp[i]));
    i++;
    }
     
    tags.setString("title", "Great banter"); // THIS IS LINE 40
    tags.setString("author", "Sheep");
    tags.set("pages", nPages);
     
    nmsCopy.setTag(tags);
    book.setAmount(1);
     
    return (ItemStack) book;
    }
    
    Thanks in advance c:

    Bump? :(

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

    InfamousSheep

    Yeah I am now, I fixed it. I thought I was receiving the "Invalid book tag" error from using BookMeta so I decided to use NBT. It's old code I recoding XD
     
Thread Status:
Not open for further replies.

Share This Page