Jump to content

[1.10.2] NPE on getRegistryName


KeeganDeathman

Recommended Posts

Post your code, we're not psychic.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Here's a sample block declaration

labstuffBlocks.add(blockAcceleratorPowerInput = new BlockAcceleratorPowerInput().setRegistryName("labstuff","blockAcceleratorPowerInput").setCreativeTab(tabLabStuff));

 

And my registry code

for(Block block : labstuffBlocks)
	{
		GameRegistry.register(block, block.getRegistryName());
		GameRegistry.register(Item.getItemFromBlock(block).setRegistryName(block.getRegistryName()), block.getRegistryName());
	}

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

Betcha it's this part here:

Item.getItemFromBlock(block)

 

Just because you called GameRegistry.register on a block does not mean your block has an item.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Interesting, that must be new.

However, it also happened in this(now since reworked) functions in a block class

@Override
public boolean isOpaqueCube(IBlockState state)
{
	if(getRegistryName().getResourcePath().contains("Glass") || getRegistryName().getResourcePath().contains("Rotor"))
		return false;
	return true;
}

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

Interesting, that must be new.

However, it also happened in this(now since reworked) functions in a block class

@Override
public boolean isOpaqueCube(IBlockState state)
{
	if(getRegistryName().getResourcePath().contains("Glass") || getRegistryName().getResourcePath().contains("Rotor"))
		return false;
	return true;
}

If you are getting a NPE just run a check to see if it is != null. Though I can not see the error report to give you anymore guidance.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

If the NPE is caused by

getRegistryName()

, then either the item/block you are trying to get the registry name of, does not have a registry name, or you are trying to access the registry name before you actually do set it.

 

If the NPE is caused by the, as mentioned,

Item.getItemFromBlock(block)

, then skip that method altogether. Instead, create an

ItemBlock

using the block as the passed parameter, and then register that.

ItemBlock is instantiated just like an ItemStack.

 

 

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

I switched to set and getRegistryName(), but now whenever i use the getter, I get an NPE.

Why?

You asked about an NPE without posting the crash report. Perhaps the forum needs a banner or sticky rules to warn against that again. As Draco says, we're not psychic.

 

Rerun your code in the debugger (setting a breakpoint ahead of the crash point). Examine the fields about to be used in the crash. See what is null. Fix it.

 

Further, since order of execution is often the cause of an NPE, we need to see whole classes, not just lines out of context. You could also put print statements in both your get and set to see which runs first (then use the debugger to examine the call stack).

 

Finally, when referring to a class's methods and fields that are not static, get into the habit of prefixing them with "this."

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Finally, when referring to a class's methods and fields that are not static, get into the habit of prefixing them with "this."

 

That's completely personal preference and doesn't have any affect on the compiled code (excepting overloaded parameters). I personally don't use

this

because I feel it's unnecessarily verbose and doesn't provide any valuable information.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

Actually, using "this" is a good habit because it will sometimes remind you when you that you have a static vs instance conflict (at least it will have you thinking about it). Well, you might never do anything that careless, but if I revisit code after months away doing something else, I sometimes break it, and I like having Eclipse tell me so sooner rather than later.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

I have an IDE that formats static in italics, so I don't have that problem.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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.