Jump to content

An anomalous error in my tile entity that is just there in the log and is totally weird


Recommended Posts

Posted (edited)

So I'm programming a tile entity for an altar block which uses some code to store an item.

	    public void readFromNBT(NBTTagCompound compound)
	    {
	        super.readFromNBT(compound);
	        this.loadFromNbt(compound, true);
	    }

	    public NBTTagCompound writeToNBT(NBTTagCompound compound)
	    {
	    	NBTTagCompound itemTag = new NBTTagCompound();
	    	itemTag.setString("id", this.currentItem.getItem().getRegistryName().getResourceDomain() + ':' + this.currentItem.getItem().getRegistryName().getResourcePath());
	    	itemTag.setInteger("count", this.currentItem.getCount());
	    	itemTag.setInteger("data", this.currentItem.getItemDamage());
	    	compound.setTag("item", itemTag);
	    	compound.setBoolean("isValid", this.isValidAltar);
	    	super.writeToNBT(compound);
	    	return compound;
	    }
	    public void loadFromNbt(NBTTagCompound compound, boolean isLogging)
	    {
	        NBTTagCompound itemTag = (NBTTagCompound) compound.getTag("item");
	        String itemId = itemTag.getString("id");
	        Item item = GameRegistry.findRegistry(Item.class).getValue(new ResourceLocation(itemId));
	        int count = itemTag.getInteger("count");
	        int damage = itemTag.getInteger("data");
	        this.currentItem = new ItemStack(item, count, damage);
	        this.isValidAltar = compound.getBoolean("isValid");
	        if(isLogging)
	        {
	        	QuickLogger.log("itemTag = " + itemTag.toString() + "\nitemId = " + itemId + "\ncount = " + count + "\ndata = " + damage + "\nisAltarValid = " + compound.getBoolean("isValid"));
	        }
	    }

and I keep getting this error in the log even though everything stores and loads seemingly fine, it raises a java.lang.NullPointerException on the line in loadFromNbt() which gets the String itemId

Here's the little error traceback thing

[16:30:23] [main/FATAL] [minecraft/Minecraft]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_191]
	at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_191]
	at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1177) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_191]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_191]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.NullPointerException
	at thetrueskeptic.ebtks.tileentity.TileEntityAltar.loadFromNbt(TileEntityAltar.java:108) ~[TileEntityAltar.class:?]
	at thetrueskeptic.ebtks.tileentity.TileEntityAltar.readFromNBT(TileEntityAltar.java:91) ~[TileEntityAltar.class:?]
	at net.minecraft.tileentity.TileEntity.handleUpdateTag(TileEntity.java:361) ~[TileEntity.class:?]
	at net.minecraft.client.network.NetHandlerPlayClient.handleChunkData(NetHandlerPlayClient.java:836) ~[NetHandlerPlayClient.class:?]
	at net.minecraft.network.play.server.SPacketChunkData.processPacket(SPacketChunkData.java:110) ~[SPacketChunkData.class:?]
	at net.minecraft.network.play.server.SPacketChunkData.processPacket(SPacketChunkData.java:20) ~[SPacketChunkData.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_191]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_191]
	at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
	... 15 more


 

Edited by TastesLikeBleach
Accidentally hit shift + enter like I was on discord which posted it before I was done.
Posted

Post your code as a GitHub repository. We can’t see line numbers on the forums

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Well, only thing I can say for sure is that something is null in TileEntityAltar line 108
 

Caused by: java.lang.NullPointerException
	at thetrueskeptic.ebtks.tileentity.TileEntityAltar.loadFromNbt(TileEntityAltar.java:108) ~[TileEntityAltar.class:?]

 

Posted (edited)

1. Indicate which line is line 108.

2. Add the @Override annotation to your methods.

3. Why are you calling loadFromNbt in your TileEntity#readFromNBT? The point of TileEntity#readFromNBT is to read the tile entity's data from the NBT. There is no need for creating another method.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
2 hours ago, DavidM said:

1. Indicate which line is line 108.

2. Add the @Override annotation to your methods.

	    public void loadFromNbt(NBTTagCompound compound, boolean isLogging)
	    {
	        NBTTagCompound itemTag = (NBTTagCompound) compound.getTag("item");
	      108 >>> String itemId = itemTag.getString("id");
	        Item item = GameRegistry.findRegistry(Item.class).getValue(new ResourceLocation(itemId));
	        int count = itemTag.getInteger("count");
	        int damage = itemTag.getInteger("data");
	        this.currentItem = new ItemStack(item, count, damage);
	        this.isValidAltar = compound.getBoolean("isValid");
	        if(isLogging)
	        {
	        	QuickLogger.log("itemTag = " + itemTag.toString() + "\nitemId = " + itemId + "\ncount = " + count + "\ndata = " + damage + "\nisAltarValid = " + compound.getBoolean("isValid"));
	        }
	    }

I should've overridden those methods, I'll do that now

Posted (edited)

1. Use ItemStack#serialize and ItemStack#deserialize to save your item in the altar. There is already built-in approaches to store inventory/itemstack to NBT. Don't reinvent the wheel.

2. itemTag is null, thus causing the error.

Edited by DavidM
Typo. Thanks Laike_Endaril.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
1 hour ago, TastesLikeBleach said:

Alright show's over, using @Override on the read and write methods fixed it.

Adding @Override only tells your IDE that you intend to override a method. It does not have any affect of the flow of a program. 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
5 hours ago, TastesLikeBleach said:

using @Override on the read and write methods fixed it.

1. @Override has absolutely no effect on the running of your code.

2. Again, do not build your own way of serializing an ItemStack. There is already a built-in method. In addition, your way of serializing did not include the NBT attached to the ItemStack.

 

4 hours ago, Laike_Endaril said:

itemTag is the thing which is null

Oops typo. I meant itemTag. Thanks for the correction.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.