Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So before I changed this method and to the latest version of forge, this was working, but not I am having a ton of repetitive crashes and I have NO idea what is causing them, I get a NullPointerException even when the items are not null.

 

This is the crash:

 

 

[17:32:43] [Client thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.client.event.RenderGameOverlayEvent$Text@396f3e11:

java.lang.NullPointerException

at com.garmora.client.gui.InGameHUD.renderItemTexture(InGameHUD.java:151) ~[inGameHUD.class:?]

at com.garmora.client.gui.InGameHUD.drawArmor(InGameHUD.java:71) ~[inGameHUD.class:?]

at com.garmora.client.gui.InGameHUD.onRender(InGameHUD.java:39) ~[inGameHUD.class:?]

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_16_InGameHUD_onRender_RenderGameOverlayEvent.invoke(.dynamic) ~[?:?]

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55) ~[ASMEventHandler.class:?]

at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138) [EventBus.class:?]

at net.minecraftforge.client.GuiIngameForge.renderHUDText(GuiIngameForge.java:676) [GuiIngameForge.class:?]

at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:159) [GuiIngameForge.class:?]

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115) [EntityRenderer.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1115) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_72]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_72]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

[17:32:43] [Client thread/ERROR] [FML]: Index: 1 Listeners:

[17:32:43] [Client thread/ERROR] [FML]: 0: NORMAL

[17:32:43] [Client thread/ERROR] [FML]: 1: ASM: com.garmora.client.gui.InGameHUD@69196cf1 onRender(Lnet/minecraftforge/client/event/RenderGameOverlayEvent;)V

[17:32:44] [server thread/INFO]: Stopping server

[17:32:44] [server thread/INFO]: Saving players

[17:32:44] [server thread/INFO]: Saving worlds

[17:32:44] [server thread/INFO]: Saving chunks for level '1.8 Forge'/Overworld

[17:32:44] [server thread/INFO]: Saving chunks for level '1.8 Forge'/Nether

[17:32:44] [server thread/INFO]: Saving chunks for level '1.8 Forge'/The End

[17:32:44] [server thread/INFO] [FML]: Unloading dimension 0

[17:32:44] [server thread/INFO] [FML]: Unloading dimension -1

[17:32:44] [server thread/INFO] [FML]: Unloading dimension 1

[17:32:44] [server thread/INFO] [FML]: Applying holder lookups

[17:32:44] [server thread/INFO] [FML]: Holder lookups applied

[17:32:45] [Client thread/FATAL]: Unreported exception thrown!

java.lang.NullPointerException

at com.garmora.client.gui.InGameHUD.renderItemTexture(InGameHUD.java:151) ~[inGameHUD.class:?]

at com.garmora.client.gui.InGameHUD.drawArmor(InGameHUD.java:71) ~[inGameHUD.class:?]

at com.garmora.client.gui.InGameHUD.onRender(InGameHUD.java:39) ~[inGameHUD.class:?]

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_16_InGameHUD_onRender_RenderGameOverlayEvent.invoke(.dynamic) ~[?:?]

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55) ~[ASMEventHandler.class:?]

at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]

at net.minecraftforge.client.GuiIngameForge.renderHUDText(GuiIngameForge.java:676) ~[GuiIngameForge.class:?]

at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:159) ~[GuiIngameForge.class:?]

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115) ~[EntityRenderer.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1115) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_72]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_72]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

[17:32:45] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: ---- Minecraft Crash Report ----

// But it works on my machine.

 

Time: 23/06/15 5:32 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at com.garmora.client.gui.InGameHUD.renderItemTexture(InGameHUD.java:151)

at com.garmora.client.gui.InGameHUD.drawArmor(InGameHUD.java:71)

at com.garmora.client.gui.InGameHUD.onRender(InGameHUD.java:39)

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_16_InGameHUD_onRender_RenderGameOverlayEvent.invoke(.dynamic)

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55)

at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at net.minecraftforge.client.GuiIngameForge.renderHUDText(GuiIngameForge.java:676)

at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:159)

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1115)

at net.minecraft.client.Minecraft.run(Minecraft.java:376)

at net.minecraft.client.main.Main.main(Main.java:117)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

 

 

These are the methods:

 

 

@SubscribeEvent

public void onRender(RenderGameOverlayEvent event)

{

if (event.type == RenderGameOverlayEvent.ElementType.TEXT && !mc.gameSettings.showDebugInfo)

{

drawArmor(100, 10, 8, 8 ); // Space here so that this page will not read it as a smiley face...

}

}

 

private void drawArmor(int x, int y, int width, int height)

{

String enchants = null;

 

for (int slot = 2; slot < 4; ++slot)

{

ItemStack stack = this.mc.thePlayer.inventory.armorInventory[slot];

if (stack == null) continue;

boolean enchanted = stack.isItemEnchanted();

enchants = showEnchant(enchanted ? stack.getEnchantmentTagList() : null);

String dur = getDamageString(stack);

renderItemTexture(x, y * (slot - 2), stack, width, height); // This causes a crash

}

for (int slot = 0; slot < 2; ++slot)

{

ItemStack stack = this.mc.thePlayer.inventory.armorInventory[slot];

if (stack == null) continue;

boolean enchanted = stack.isItemEnchanted();

enchants = showEnchant(enchanted ? stack.getEnchantmentTagList() : null);

String dur = getDamageString(stack);

renderItemTexture(x, y * slot, stack, width, height); // This causes a crash

}

if (this.mc.thePlayer.inventory.getCurrentItem() != null)

{

boolean enchanted = this.mc.thePlayer.inventory.getCurrentItem().isItemEnchanted();

enchants = showEnchant(enchanted ? this.mc.thePlayer.inventory.getCurrentItem().getEnchantmentTagList() : null);

String dur = getDamageString(this.mc.thePlayer.inventory.getCurrentItem());

ItemStack stack = this.mc.thePlayer.inventory.getCurrentItem();

renderItemTexture(x, y + 100, stack, width, height); // This causes a crash

}

}

 

public void renderItemTexture(int x, int y, ItemStack stack, int width, int height)

{

IBakedModel ibakedmodel = mc.getRenderItem().getItemModelMesher().getItemModel(new ItemStack(stack.getItem()));

TextureAtlasSprite textureAtlasSprite = mc.getTextureMapBlocks().getAtlasSprite(ibakedmodel.getTexture().getIconName()); // This is where the crash points to

if (stack.getItem() == Item.getItemFromBlock(Blocks.standing_banner) || stack.getItem() instanceof ItemBlock || Block.getBlockFromItem(stack.getItem()) != null) return; // Prevents SOME crashes

mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);

 

if (stack.getItem().isDamageable())

{

GlStateManager.pushMatrix();

double damage = stack.getItem().getDurabilityForDisplay(stack);

int j1 = (int) Math.round(13.0D - damage * 13.0D);

int k = (int) Math.round(255.0D - damage * 255.0D);

GlStateManager.disableDepth();

GlStateManager.disableTexture2D();

GlStateManager.disableAlpha();

GlStateManager.disableBlend();

Tessellator tessellator = Tessellator.getInstance();

WorldRenderer worldrenderer = tessellator.getWorldRenderer();

int l = 255 - k << 16 | k << 8;

int i1 = (255 - k) / 4 << 16 | 16128;

drawRect(worldrenderer, x + 6, y + 9, 13, 2, 0);

drawRect(worldrenderer, x + 6, y + 9, 12, 1, i1);

drawRect(worldrenderer, x + 6, y + 9, j1, 1, l);

GlStateManager.enableBlend();

GlStateManager.enableAlpha();

GlStateManager.enableTexture2D();

GlStateManager.enableDepth();

GlStateManager.popMatrix();

}

 

if (stack.hasEffect())

{

this.renderItemIntoGUI(stack, x, y, ibakedmodel, 0.5F);

}

else

{

renderTexture(x, y, textureAtlasSprite, width, height, 0);

}

 

int y1 = y;

y1 += y;

GlStateManager.pushMatrix();

GlStateManager.scale(0.5F, 0.5F, 0.5F); // Scales so that the text is not so large

int color = 16777215;

if (stack.hasEffect()) color = 16760852;

mc.fontRendererObj.drawString(getDamageString(stack), x + 12, y1 + 10, color);

GlStateManager.color(1.0F, 1.0F, 1.0F); // Fixes some lighting glitches

GlStateManager.popMatrix();

}

 

public void renderTexture(int x, int y, TextureAtlasSprite atlas, int width, int height, double zLevel)

{

Tessellator tessellator = Tessellator.getInstance();

WorldRenderer worldrenderer = tessellator.getWorldRenderer();

worldrenderer.startDrawingQuads();

worldrenderer.addVertexWithUV((double) (x + 0), (double) (y + height), (double) zLevel, (double) atlas.getMinU(), (double) atlas.getMaxV());

worldrenderer.addVertexWithUV((double) (x + width), (double) (y + height), (double) zLevel, (double) atlas.getMaxU(), (double) atlas.getMaxV());

worldrenderer.addVertexWithUV((double) (x + width), (double) (y + 0), (double) zLevel, (double) atlas.getMaxU(), (double) atlas.getMinV());

worldrenderer.addVertexWithUV((double) (x + 0), (double) (y + 0), (double) zLevel, (double) atlas.getMinU(), (double) atlas.getMinV());

tessellator.draw();

}

 

 

TextureAtlasSprite textureAtlasSprite = mc.getTextureMapBlocks().getAtlasSprite(ibakedmodel.getTexture().getIconName()); // This is where the crash points to

Whenever you get a NULL pointer exception, the first thing you should do is put a break point on that line and fire up the debugger.

 

If you are not comfortable doing that, then you can still quickly debug it by putting everything on its own line:

TextureAtlasSprite textureAtlasSprite = mc
    .getTextureMapBlocks()
    .getAtlasSprite(ibakedmodel
        .getTexture()
        .getIconName()
    );

Now when you run your code again, you will find out EXACTLY which of those is null.

So I did that and it appears to go null on the .getIconName() method

So... you can fix it now, right, since you know what is null?

 

Specifically: "Calling the instance method of a null object."

 

i.e. You cannot call a class method if you do not have an object of that class. You are trying to call getIconName() on a NULL object.

  • Author

Well I would assume I am handling it being null because

if (stack == null) continue;
and
if (this.mc.thePlayer.inventory.getCurrentItem() != null)

should handle it, correct?

 

Well I would assume I am handling it being null because

if (stack == null) continue;
and
if (this.mc.thePlayer.inventory.getCurrentItem() != null)

should handle it, correct?

Is that the line that your crash log pointed to when it gave you the NPE? No, it isn't, i.e. this is not where the problem is.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.