In readFromNBT, you never set item to anything other than null, so it's still null when you try to call ItemStack#deserializeNBT on it. Calling a method on a null value throws a NullPointerException.
Use the ItemStack(NBTTagCompound) constructor to read an ItemStack from NBT.
That said, you should generally be storing items in an IItemHandler inventory, even if it only has a single slot. If you use ItemStackHandler, you can use the INBTSerializable methods implemented by it to read from/write to NBT.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Im trying to load a Item from and to NBT but i get a NPE while loading.
In writeToNBT:
In readFromNBT:
Any Idea what i made have done wrong?
In readFromNBT, you never set item to anything other than null, so it's still null when you try to call ItemStack#deserializeNBT on it. Calling a method on a null value throws a NullPointerException.
Use the ItemStack(NBTTagCompound) constructor to read an ItemStack from NBT.
That said, you should generally be storing items in an IItemHandler inventory, even if it only has a single slot. If you use ItemStackHandler, you can use the INBTSerializable methods implemented by it to read from/write to NBT.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.