Jump to content

Having trouble itterating through all items in the game


zeetillz

Recommended Posts

Hi,

 

I am currently trying to iterate through Item.itemsList

 

e.g

 

    Item[] allItems = Item.itemsList;;

            for (int i = 0; i < allItems.length; i++)
            {
            	allItems[i].getStatName();
                // to display in GUI
                // to display in config file
            }

 

But overtime I do i get a java.lang.NullPointerException

I know that allItems.getStatName(); is causing the issue since if I were to write to a config file, say, the value of 'i', within the loop, it works.

 

Is there any way to fix this or are there any other alternatives (I am C# developer so not everything in Java is apparent to me)

 

Thanks in advance.

Link to comment
Share on other sites

NullPointerException usually means that there is something wrong with your item ids. It would make sense that you aren't getting NullPointerException immediately because it is a loop. Go back to your item ids and make sure that none of them conflict and that all of them point to something.

 

I hope that this helped you!

Link to comment
Share on other sites

Right ok, thanks for this, but the thing is I haven't added any items, and in theory I should just be looping through all the default items :(

 

What vanilla item has the id 3877?

 

That's right, NOTHING.

 

What is an item that is NOTHING?  Why it's NULL.

 

Congradulations, you have a NPE.

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

Right ok, thanks for this, but the thing is I haven't added any items, and in theory I should just be looping through all the default items :(

 

What vanilla item has the id 3877?

 

That's right, NOTHING.

 

What is an item that is NOTHING?  Why it's NULL.

 

Congradulations, you have a NPE.

 

OHHHHHHH, well that makes sense, doh, silly me.

 

so

if(item == null){
    continue;
}

should fix the issue

 

Thanks a bunch! :D

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.