- public void NoItemNull() {
- try {
- if(Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() != null) {//问题来源
- Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.getHeldItem().getItem().getRegistryName(), 20, 70, Color.BLACK.getRGB());//获得并渲染玩家手速拿的物品的注册名字
- }
- }catch(Exception e) {e.printStackTrace();}
- }
疑问:进入游戏会导致游戏崩溃
我是想要他用RenderGameOverlayEvent.Text事件渲染文字在游戏页面
我试了很多次 可能会发生的错误
但是无法解决这个问题 *可能我比较菜
问题来源就是这个try断点里面
?1.12.2获取物品不见有问题
1.8就有问题了? 各位这是怎么回事?
求解

附上错误报告:

- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: java.lang.NullPointerException
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at io.github.enaiLusoaix.minecraft.qaq.NoItemNull(qaq.java:87)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at io.github.enaiLusoaix.minecraft.qaq.base(qaq.java:65)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_qaq_base_PlayerTickEvent.invoke(.dynamic)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:49)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:140)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPreTick(FMLCommonHandler.java:352)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:248)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:366)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:347)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:36)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:10)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.util.Util.runTask(Util.java:22)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:681)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:159)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548)
- [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: at java.lang.Thread.run(Thread.java:748)
getHeldItem().getItem() != null
改为
getHeldItem() != null
试试
改为
getHeldItem() != null
试试