Posted November 3, 201311 yr 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.
November 3, 201311 yr 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!
November 3, 201311 yr Author 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
November 3, 201311 yr 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.
November 3, 201311 yr Author 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!
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.