Jump to content

java.lang.NullPointerException?


Pardeep

Recommended Posts

I get this error for java.lang.NullPointerException

---- Minecraft Crash Report ----
// This doesn't make any sense!

Time: 04/09/13 17:36
Description: Exception in server tick loop

java.lang.NullPointerException
at ss97.cm.minecoin.WelcomeMessages.onPlayerLogin(WelcomeMessages.java:15)
at cpw.mods.fml.common.registry.GameRegistry.onPlayerLogin(GameRegistry.java:354)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePlayerLogin(FMLNetworkHandler.java:299)
at net.minecraft.server.management.ServerConfigurationManager.initializeConnectionToPlayer(ServerConfigurationManager.java:156)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:97)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:689)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:585)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
Minecraft Version: 1.6.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_25, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 878602264 bytes (837 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 2 (112 bytes; 0 MB) allocated, 2 (112 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v8.04 FML v6.2.35.804 Minecraft Forge 9.10.0.804 4 mods loaded, 4 mods active
mcp{8.04} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{6.2.35.804} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{9.10.0.804} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
ss97cm{1.0} [ss97cm] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player508'/2, l='hi`', x=-113.50, y=4.00, z=1126.50]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

The classes this conerns:

 

The WelcomeMessages class that implements IPlayerTracker

package ss97.cm.minecoin;

import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.IPlayerTracker;

public class WelcomeMessages implements IPlayerTracker
{
//Instances
public EntityPlayerBalances entityplayerbalances;

@Override
public void onPlayerLogin(EntityPlayer player)
{
	player.addChatMessage("§6Currency Mod v0.1 loaded");
	player.addChatMessage("Current balance in your wallet is §6" + entityplayerbalances.getMinecoinBalanceWallet() + " §FMinecoins");
	player.addChatMessage("Current balance in your bank account is §6" + entityplayerbalances.getMinecoinBalanceBank() + " §FMinecoins");
}

@Override
public void onPlayerLogout(EntityPlayer player)
{
	// TODO Auto-generated method stub
}

@Override
public void onPlayerChangedDimension(EntityPlayer player)
{
	// TODO Auto-generated method stub
}

@Override
public void onPlayerRespawn(EntityPlayer player) 
{
	// TODO Auto-generated method stub
}

}

The EntityPlayerBalances class that WelcomeMessages gets some integer values from (implements IExtendedEntityProperties)

package ss97.cm.minecoin;

 

import net.minecraft.entity.player.*;

import net.minecraft.entity.*;

import net.minecraft.nbt.*;

import net.minecraft.world.*;

import net.minecraftforge.common.*;

 

public class EntityPlayerBalances implements IExtendedEntityProperties

{

public EntityPlayer player;

 

//Dat Variable that holds the amount of coins a player has in the "wallet"

public int minecoinBalanceWallet = 0;

 

//Dat Variable that holds the amount of coins a player has in the bank

public int minecoinBalanceBank = 0;

 

public final static String EXT_PROP_NAME = "EntityPlayerMinecoinBalances";

 

public EntityPlayerBalances(EntityPlayer player)

{

this.player = player;

}

 

@Override

public void saveNBTData(NBTTagCompound compound)

{

compound.setInteger("MinecoinBalanceWallet", this.minecoinBalanceWallet);

compound.setInteger("MinecoinBalanceBank", this.minecoinBalanceBank);

}

 

@Override

public void loadNBTData(NBTTagCompound compound)

{

this.minecoinBalanceWallet = compound.getInteger("MinecoinBalanceWallet");

this.minecoinBalanceBank = compound.getInteger("MinecoinBalanceBank");

}

 

@Override

public void init(Entity entity, World world)

{

 

}

 

//CUSTOM METHODS

 

//Used to get the player's wallet balance

public int getMinecoinBalanceWallet()

{

return this.minecoinBalanceWallet;

}

//Used to get the player's bank balance

public int getMinecoinBalanceBank()

{

return this.minecoinBalanceBank;

}

 

//Used to add par1 to the player's wallet balance

public void addToMinecoinBalanceWallet(int par1)

{

this.minecoinBalanceWallet += par1;

}

 

//Used to add par1 to the player's bank balance

public void addToMinecoinBalanceBank(int par1)

{

this.minecoinBalanceBank += par1;

}

 

//Used to reset the player's wallet balance to 0 (main use: when the player dies)

public void resetMinecoinBalanceWallet()

{

this.minecoinBalanceWallet = 0;

}

}

 

The EventHandler that registers this EntityPlayerBalances class

package ss97.cm.minecoin;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;

public class EventHandler_PlayerBalances
{
public Minecraft mc;

//Event for registering EntityPlayerBalances
@ForgeSubscribe
public void onEntityConstructing(EntityConstructing event)
{
	if (event.entity instanceof EntityPlayer && event.entity.getExtendedProperties(EntityPlayerBalances.EXT_PROP_NAME) == null)
	{
		event.entity.registerExtendedProperties(EntityPlayerBalances.EXT_PROP_NAME, new EntityPlayerBalances((EntityPlayer)event.entity));
	}
}
}

 

Methods in Init method of the base class that are relevant

MinecraftForge.EVENT_BUS.register(new EventHandler_PlayerBalances());
GameRegistry.registerPlayerTracker(new WelcomeMessages());

 

 

In the crash report at:

java.lang.NullPointerException
at ss97.cm.minecoin.WelcomeMessages.onPlayerLogin(WelcomeMessages.java:15)

this takes me to this line in the WelcomeMessages class:

player.addChatMessage("Current balance in your wallet is §6" + entityplayerbalances.getMinecoinBalanceWallet() + " §FMinecoins");

Hopefully this will help you resolve the error.

 

Thanks in advance.

Link to comment
Share on other sites

Place a breakpoint at WelcomeMessages.java:15 and see what is null during runtime?

I placed a breakpoint at that point and the same error log appears. It's something to do with the line I mentioned in the main post:

player.addChatMessage("Current balance in your wallet is §6" + entityplayerbalances.getMinecoinBalanceWallet() + " §FMinecoins");

I just don't see what the problem is.

Link to comment
Share on other sites

So how would I go about resolving this?

Should I place the method that registers the WelcomeMessage class before the one that registers the balances class?

 

Consider the logic behind that for a second, what would happen if you do that, would the thing still be null? :)

or

go try things ;)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I figured it out now.

Just passed the class instance as a parameter

public EntityPlayerBalances entityplayerbalances;

@Override
public void onPlayerLogin(EntityPlayer player)
{
	entityplayerbalances = new EntityPlayerBalances(player);
	player.addChatMessage("§6Currency Mod v0.1 loaded");
	player.addChatMessage("Current balance in your wallet is §6" + entityplayerbalances.getMinecoinBalanceWallet() + " §FMinecoins");
	player.addChatMessage("Current balance in your bank account is §6" + entityplayerbalances.getMinecoinBalanceBank() + " §FMinecoins");
}

THanks for your help though

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.