Jump to content

[1.7.10] [Solved] NullPointerException, because the constructor is never called.


Recommended Posts

Hello, I am having a little bit of trouble with the following

code, I am trying to make a seed plantable on farmland which

works fine if I specify which block is suppose to be placed directly in the main seedPlacement class

however I would like to use this class as a reference for future seeds and so I wish to use a variable to assign the block.


However the variable is never assigned because it is never called in my constructor.

And I am currently out of ideas what to try.


Any help will be much appreciated!


Regards, Venomous


The seed item class:

public class ItemLettuceSeeds extends seedPlacement{

public ItemLettuceSeeds() {
	super(0, 0.3f, RealismMod.blockLettuceCrop, Blocks.farmland);



The main seed class:

public class seedPlacement extends ItemFood implements IPlantable
    private final Block theBlockPlant;
    private final Block soilId;

    public seedPlacement(int parHealAmount, float parSaturationModifier, Block parBlockPlant, Block parSoilBlock)
        super(parHealAmount, parSaturationModifier, false);
        theBlockPlant = parBlockPlant; //not getting assigned
        soilId = parSoilBlock; //not getting assigned
    //constructor isn't even being called

    public boolean onItemUse(ItemStack parItemStack, EntityPlayer parPlayer, 
          World parWorld, int parX, int parY, int parZ, int par7, float par8, 
          float par9, float par10)
     // not sure what this parameter does, copied it from the potato class
        if (par7 != 1)
            return false;
        else if (parPlayer.canPlayerEdit(parX, parY+1, parZ, par7, parItemStack))
        	System.out.println("Result: " + theBlockPlant + " and " + soilId);  //Result: Null and Null

            if (parWorld.getBlock(parX, parY, parZ).canSustainPlant(parWorld, 
                  parX, parY, parZ, ForgeDirection.UP, this) && parWorld
                  .isAirBlock(parX, parY+1, parZ))
            	//crashes cause null pointer exception since theBlockPlant is never assigned.
                //parWorld.setBlock(parX, parY+1, parZ, theBlockPlant);

                return true;
                return false;
            return false;


When in doubt, use brute force.

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.

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.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.