Jump to content

Null pointer after if statement


Schleim_time

Recommended Posts

@Override
    public void onContainerClosed(EntityPlayer playerIn) {
        for(int x = 0; x < 9; x++) {
            if(tyleentity.getStackInSlot(x)!=null||tyleentity.getStackInSlot(x)!= new ItemStack(Items.AIR).EMPTY) {
                itemlist.add(tyleentity.getStackInSlot(x));
            }
        }
        if(!itemlist.isEmpty()) {
            for(ItemStack item : itemlist) {
            playerIn.inventory.addItemStackToInventory(item);
            }
        }
        tyleentity.clear();
        itemlist.clear();
    }

 

i want to let the player get the items back on closing the table but for some reson its crashes because of an null pointer on the line i marked, idk why because i already asked if it is null bevore

Link to comment
Share on other sites

tyleentity.getStackInSlot(x)!=null||tyleentity.getStackInSlot(x)!= new ItemStack(Items.AIR).EMPTY

what is this, use stack.isEmpty

 

and plz format your code it is really hard to read

 

did you ever set itemlist ?

Edited by loordgek
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.