Posted September 4, 201312 yr 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.
September 4, 201312 yr Place a breakpoint at WelcomeMessages.java:15 and see what is null during runtime? If you guys dont get it.. then well ya.. try harder...
September 4, 201312 yr Author 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.
September 4, 201312 yr entityplayerbalances is null. It isn't set in WelcomeMessages before player login.
September 4, 201312 yr Author entityplayerbalances is null. It isn't set in WelcomeMessages before player login. 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?
September 4, 201312 yr 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...
September 4, 201312 yr Author 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
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.