Jump to content

getIcon() for BlockDoor always returning NullPointerException [SOLVED]


Recommended Posts

Posted

Hello, so this issue is, whenever I run my mod to generate a custom door, the getIcon() method is always called immediately, before the registerBlockIcons() method. Therefore returning a NullPointerException, I have tried to check if the icon I'm returning is equal to null by using if (icon != null). The issue was, nothing I was returning in the else statement was helping me. Another forum has had the same problem;

 

https://github.com/Chicken-Bones/ForgeMultipart/issues/86#issuecomment-25778634

 

However, the suggested method of solving it, by checking for null and using a pointer if it was null, was not in any way helpful.

 

Relevant Icon Code:

 

 

  Reveal hidden contents

 

 

Relevant Crash Report:

 

 

  Reveal hidden contents

 

 

If I missed out any additional code or information I should have added, please notify me. Thanks for reading.

Posted

Well, if you look closely at your code you're checking if icons[0] is null and then you are returning it (you assign it to newIcon, but then newIcon will be null)  -- so that is probably why you're getting the null pointer exception. 

 

The more interesting question is why icons[0] is null in the first place.  Your registration method looks correct to me.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I've tried just returning icons[0] as well, the code I posted was the alternative suggested. As I said in the first post, I believe the error lies in the fact it is calling getIcons() before anything else (Before registering them), therefore returning null. I also have no idea of changing the order of calling it.

Posted

I just realized something I have from another class..

 

How come this works

 

 

  Reveal hidden contents

 

 

But not this code?

 

 

  Reveal hidden contents

 

 

 

Also, I have tried to use console print, and it prints inside of the main, but whenever I place the block it auto-crashes Minecraft so it never shows anything inside of getIcons. However, if I place it in registerBlockIcon, it prints the statement during Minecraft startup. So why is it still null while passing the icons[0]?

 

Edit:

I printed text and icons[0] inside of registerIcons, it printed the name of the png file with some weird syntax, so I think it is assigned properly.

Posted

Can you show the code where you declare the icons[] array?  Do you do it differently in each case, because in your first example it seems you've already got a length implying that the array is declared with a size already, and possibly already initialized somehow...

 

Can you show the code where you register the block itself?

 

It is possible that perhaps you're somehow placing a block that is improperly registered I guess. 

 

But it is a strange problem, as the code generally looks okay to me.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Here's my full door class for your reference.

 

 

  Reveal hidden contents

 

 

I tried several different locations of calling icons = new IIcon[2];

 

Full Item Class

 

 

  Reveal hidden contents

 

 

Also, any println statements in the getBlockTexture method are never called. This might be of use as well, here is the relevant BlockDoor class that gives the error.

 

BlockDoor Relevant Methods

 

 

  Reveal hidden contents

 

 

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.