Résolu NPE
-
Salut j’ai un NPE dans le constructeur de mon PacketRenderInterpole
Code générateur du packet (packet Side.SERVER)
public static class Handler implements IMessageHandler <packetinterpole, imessage="">{ String[] recherches; @Override public IMessage onMessage(PacketInterpole message, MessageContext ctx) { int search = 0; String[] test = {"Test1","Test2","Test3","Test4"}; List <entityplayermp>players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for(EntityPlayerMP player : players) { EEPRestrained props = EEPRestrained.get(player); if(props.montantInterpol[0] != 0) { recherches[search] = player.getDisplayName(); search++; } } ModAltisCraft.instance.network.sendTo(new PacketRenderInterpole(test),(EntityPlayerMP)ctx.getServerHandler().playerEntity); return null; } }
Side.CLIENT celui ci
package fr.altiscraft.benjaminloison.packets; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.altiscraft.benjaminloison.common.ModAltisCraft; import fr.altiscraft.benjaminloison.gui.GuiInterpole; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; public class PacketRenderInterpole implements IMessage { private int nbr; private String[] recherches; public PacketRenderInterpole() {} public PacketRenderInterpole(String[] recherches) { this.recherches = recherches; } @Override public void fromBytes(ByteBuf buf) { this.nbr = buf.readInt(); for(int i = 0; i < this.nbr; i++) { this.recherches* = ByteBufUtils.readUTF8String(buf); } } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.nbr); for(int i = 0; i < this.recherches.length; i++) { ByteBufUtils.writeUTF8String(buf, this.recherches*); } } public static class Handler implements IMessageHandler <packetrenderinterpole, imessage="">{ @Override @SideOnly(Side.CLIENT) public IMessage onMessage(PacketRenderInterpole message, MessageContext ctx) { Minecraft.getMinecraft().displayGuiScreen(new GuiInterpole(message.recherches)); return null; } } }
Je comprends vraiment pas robin m’a dit d’envoyer comme ça les informations pour les tableaux, je suis pas censé d’avoir de NPE dans le constructeur là…</packetrenderinterpole,></entityplayermp></packetinterpole,>
-
Et ce que tu pourrais montrer le crash report ?
EDIT : Il semblerait que quelque chose comme cela serai bienpublic class PacketRenderInterpole implements IMessage { private int nbr; private String[] recherches; public PacketRenderInterpole() {} public PacketRenderInterpole(String[] recherches) { this.nbr = recherches.length; this.recherches = recherches; } @Override public void fromBytes(ByteBuf buf) { this.nbr = buf.readInt(); recherches = new int[nbr]; for(int i = 0; i < this.nbr; i++) { this.recherches* = ByteBufUtils.readUTF8String(buf); } } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.nbr); for(int i = 0; i < this.recherches.length; i++) { ByteBufUtils.writeUTF8String(buf, this.recherches*); } }
-
Voici avec toutes les classes en question :
package fr.altiscraft.benjaminloison.packets; import java.util.Arrays; import java.util.List; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import fr.altiscraft.benjaminloison.common.ModAltisCraft; import fr.altiscraft.benjaminloison.entity.EEPRestrained; import fr.altiscraft.benjaminloison.gui.GuiInterpole; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; public class PacketInterpole implements IMessage { public PacketInterpole() {} @Override public void fromBytes(ByteBuf buf) {} @Override public void toBytes(ByteBuf buf) {} public static class Handler implements IMessageHandler <packetinterpole, imessage="">{ String[] recherches; @Override public IMessage onMessage(PacketInterpole message, MessageContext ctx) { int search = 0; String[] test = {"Test1","Test2","Test3","Test4"}; List <entityplayermp>players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for(EntityPlayerMP player : players) { EEPRestrained props = EEPRestrained.get(player); if(props.montantInterpol[0] != 0) { recherches[search] = player.getDisplayName(); search++; } } ModAltisCraft.instance.network.sendTo(new PacketRenderInterpole(test),(EntityPlayerMP)ctx.getServerHandler().playerEntity); return null; } } }
package fr.altiscraft.benjaminloison.gui; import org.lwjgl.opengl.GL11; import fr.altiscraft.benjaminloison.common.ModAltisCraft; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; public class GuiInterpole extends GuiScreen { int guiWidth = 250; int guiHeight = 200; private EntityPlayer player = Minecraft.getMinecraft().thePlayer; String[] recherches; public GuiInterpole(String[] recherches) { System.out.println(recherches); this.recherches = recherches; } @Override public void drawScreen(int x, int y, float ticks) { int guix = (width - guiWidth) / 2; int guiy = (height - guiHeight) / 2; GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/Fondinv.png")); drawTexturedModalRect(guix, guiy, 0, 0, guiWidth - 3, 15); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/BackGround.png")); drawTexturedModalRect(guix, guiy + 16, 0, 0, guiWidth - 3, 150); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/BackGround.png")); drawTexturedModalRect(guix + 5, guiy + 21, 0, 0, guiWidth - 65, 140); fontRendererObj.drawString(("InterPole"), guix + 5, guiy + 5, 0xFFFFFF); super.drawScreen(x, y, ticks); } @Override public void initGui() { int guiX = (this.width - guiWidth) / 2; int guiY = (this.height - guiHeight) / 2; int number = 4; int PosY = guiY + 23; buttonList.clear(); buttonList.add(new BoutonNoirCustom(0, guiX + 54, guiY + 168, "FERMER", 50, 20)); buttonList.add(new BoutonNoirCustom(1, guiX + 2, guiY + 168, "RETOUR", 50, 20)); buttonList.add(new BoutonNoirCustom(2, guiX + 192, guiY + 20, "PARDON", 50, 20)); buttonList.add(new BoutonNoirCustom(3, guiX + 192, guiY + 42, "AMENDE", 50, 20)); for(int i = 0; i < this.recherches.length; i++) { buttonList.add(new BoutonInvisibleCustomInterpole(number, guiX + 8, PosY, this.recherches*, guiWidth - 70, 10)); number++; PosY += 10; } super.initGui(); } @Override protected void actionPerformed(GuiButton btn) { if(btn.id == 0) { Minecraft.getMinecraft().displayGuiScreen(null); } if(btn.id == 1) { Minecraft.getMinecraft().displayGuiScreen(new GuiInv()); } } @Override public boolean doesGuiPauseGame() { return false; } }
package fr.altiscraft.benjaminloison.packets; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.altiscraft.benjaminloison.common.ModAltisCraft; import fr.altiscraft.benjaminloison.gui.GuiInterpole; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; public class PacketRenderInterpole implements IMessage { private int nbr; private String[] recherches; public PacketRenderInterpole() {} public PacketRenderInterpole(String[] recherches) { this.recherches = recherches; } @Override public void fromBytes(ByteBuf buf) { this.nbr = buf.readInt(); for(int i = 0; i < this.nbr; i++) { this.recherches* = ByteBufUtils.readUTF8String(buf); } } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.nbr); for(int i = 0; i < this.recherches.length; i++) { ByteBufUtils.writeUTF8String(buf, this.recherches*); } } public static class Handler implements IMessageHandler <packetrenderinterpole, imessage="">{ @Override @SideOnly(Side.CLIENT) public IMessage onMessage(PacketRenderInterpole message, MessageContext ctx) { Minecraft.getMinecraft().displayGuiScreen(new GuiInterpole(message.recherches)); return null; } } }
Crash (fatal error*) :
[22:01:13] [Client thread/INFO] [STDOUT]: [fr.altiscraft.benjaminloison.gui.GuiInterpole:<init>:23]: null [22:01:13] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception java.lang.NullPointerException at fr.altiscraft.benjaminloison.gui.GuiInterpole.initGui(GuiInterpole.java:55) ~[GuiInterpole.class:?] at net.minecraft.client.gui.GuiScreen.setWorldAndResolution(GuiScreen.java:294) ~[GuiScreen.class:?] at net.minecraft.client.Minecraft.displayGuiScreen(Minecraft.java:865) ~[Minecraft.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:55) ~[PacketRenderInterpole$Handler.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:1) ~[PacketRenderInterpole$Handler.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[SimpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[SimpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60] 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/:?] [22:01:13] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception java.lang.NullPointerException at fr.altiscraft.benjaminloison.gui.GuiInterpole.initGui(GuiInterpole.java:55) ~[GuiInterpole.class:?] at net.minecraft.client.gui.GuiScreen.setWorldAndResolution(GuiScreen.java:294) ~[GuiScreen.class:?] at net.minecraft.client.Minecraft.displayGuiScreen(Minecraft.java:865) ~[Minecraft.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:55) ~[PacketRenderInterpole$Handler.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:1) ~[PacketRenderInterpole$Handler.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[SimpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[SimpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60] 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/:?] [22:01:13] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception java.lang.NullPointerException at fr.altiscraft.benjaminloison.gui.GuiInterpole.initGui(GuiInterpole.java:55) ~[GuiInterpole.class:?] at net.minecraft.client.gui.GuiScreen.setWorldAndResolution(GuiScreen.java:294) ~[GuiScreen.class:?] at net.minecraft.client.Minecraft.displayGuiScreen(Minecraft.java:865) ~[Minecraft.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:55) ~[PacketRenderInterpole$Handler.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:1) ~[PacketRenderInterpole$Handler.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[SimpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[SimpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60] 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/:?] [22:01:13] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel T4Channel java.lang.NullPointerException at fr.altiscraft.benjaminloison.gui.GuiInterpole.initGui(GuiInterpole.java:55) ~[GuiInterpole.class:?] at net.minecraft.client.gui.GuiScreen.setWorldAndResolution(GuiScreen.java:294) ~[GuiScreen.class:?] at net.minecraft.client.Minecraft.displayGuiScreen(Minecraft.java:865) ~[Minecraft.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:55) ~[PacketRenderInterpole$Handler.class:?] at fr.altiscraft.benjaminloison.packets.PacketRenderInterpole$Handler.onMessage(PacketRenderInterpole.java:1) ~[PacketRenderInterpole$Handler.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[SimpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[SimpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60] 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/:?] ```</init></packetrenderinterpole,></entityplayermp></packetinterpole,>
-
Lorsque tu instancie ton Gui, la variable recherches est null et le GUI crash donc sur ```java
recherches.length -
buf.writeInt(this.nbr) nbr n’est pas définie à cdt endroit là donc le client va recevoir nbr = 0, faut que tu mettes nbr = recherches.length dans ton constructeur
-
Et recherches est null car ton paquet n’est pas bon. Ça correspond à quoi nbr ?
Ton paquet devrait être comme ça :package fr.altiscraft.benjaminloison.packets; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.altiscraft.benjaminloison.common.ModAltisCraft; import fr.altiscraft.benjaminloison.gui.GuiInterpole; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; public class PacketRenderInterpole implements IMessage { private String[] recherches; public PacketRenderInterpole() {} public PacketRenderInterpole(String[] recherches) { this.recherches = recherches; } @Override public void fromBytes(ByteBuf buf) { this.recherches = new String[buf.readInt()]; for(int i = 0; i < this.recherches.length; i++) { this.recherches* = ByteBufUtils.readUTF8String(buf); } } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.recherches.length); for(int i = 0; i < this.recherches.length; i++) { ByteBufUtils.writeUTF8String(buf, this.recherches*); } } public static class Handler implements IMessageHandler <packetrenderinterpole, imessage="">{ @Override @SideOnly(Side.CLIENT) public IMessage onMessage(PacketRenderInterpole message, MessageContext ctx) { Minecraft.getMinecraft().displayGuiScreen(new GuiInterpole(message.recherches)); return null; } } } ```</packetrenderinterpole,>
-
Mon problème c’est que j’ai pas mal de OutOfBounds ou de NPE :
String[] recherches; @SuppressWarnings("null") @Override public IMessage onMessage(PacketInterpole message, MessageContext ctx) { int search = 0; String[] recherches = null; List <entityplayermp>players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for(EntityPlayerMP player : players) { EEPRestrained props = EEPRestrained.get(player); if(props.montantInterpol[0] != 0) { recherches[search] = player.getDisplayName(); search++; } } if(search == 0) { recherches[0] = "Test"; recherches[1] = "Testou"; } ModAltisCraft.instance.network.sendTo(new PacketRenderInterpole(recherches),(EntityPlayerMP)ctx.getServerHandler().playerEntity); return null; }
J’ai revu extrèmement bien comment marche les tableaux (https://openclassrooms.com/courses/apprenez-a-programmer-en-java/les-tableaux-3) mais
“Vous pouvez aussi déclarer un tableau vide, mais celui-ci devra impérativement contenir un nombre de cases bien défini.”
Et c’est ça mon problème, je veux que mon tableau soit de base vide et qu’il y est autant de place que possible…</entityplayermp> -
Je Switch en résolu je pense trouver et me démerder pour tout ce que je veux faire avec sinon je réouvrirait merci
-
Dans ce cas utilises des listes. La taille des listes est variable contrairement aux tableaux où la taille est fixe.