Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling exceptions Java
    primarykey
    data
    text
    <p>I am trying to make a chat server that communicates with my Minecraft client and that worked fine but I can not get the client to work with the server. This is the client </p> <pre><code>public class ClientChatHandler { public static ObjectOutputStream output; public static ObjectInputStream input; public static String message = ""; public static String serverIP = "localhost"; public static Socket connection; } public ClientChatHandler(String host){ serverIP = host; } public static void startRunning(){ try{ connectToServer(); setupStreams(); whileChatting(); } catch(EOFException eofException){ Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + "\247a[Server] Client terminated the connection."); } catch(IOException ioException){ ioException.printStackTrace(); } } public static void connectToServer() throws IOException{ Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + "\247a[Server] Attempting to connect."); connection = new Socket(InetAddress.getByName(serverIP), 1337); Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + "\247a[Server] Connected to server."); } public static void setupStreams() throws IOException{ try{ output = new ObjectOutputStream(connection.getOutputStream()); output.flush(); input = new ObjectInputStream(connection.getInputStream()); } catch(NullPointerException Exception){ Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + "\247a[Server] Error creating streams. Closing connection"); } catch(IOException ioException){ Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + "\247a[Server] Error creating streams. Closing connection"); } } public static void whileChatting() throws IOException{ do{ try{ message = (String) input.readObject(); Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + message); }catch(ClassNotFoundException classNotFoundException){ Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + "\247a[Server] \2474ERROR! Connecting, closing sockets."); } }while(!message.equals("server - end")); } public static void closeCrap(){ Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + "\247a[Server] Closing connection"); try{ output.close(); input.close(); connection.close(); }catch(IOException ioException){ ioException.printStackTrace(); } } public static void sendMessage(String message){ try{ output.writeObject(message); output.flush(); Minecraft.getMinecraft().thePlayer.addChatMessage(Variables.color + message); } catch(IOException ioException){ } } public static void showMessage(final String message){ Minecraft.getMinecraft().thePlayer.addChatMessage(Methods.getLetterColor(Variables.ChatName Color) + Minecraft.getMinecraft().thePlayer.username + "\2477:\247f " + message); } </code></pre> <p>Now I keep getting <code>java.lang.NullPointerException</code> of this:</p> <pre><code>output = new ObjectOutputStream(connection.getOutputStream()); output.flush(); input = new ObjectInputStream(connection.getInputStream()); </code></pre> <p>How can I resolve this problem?</p> <p>Sorry for the lack of information but minecraft crashes and I get a null pointer exception from the above code. </p> <p>Here's some text:</p> <pre><code> java.lang.NullPointerException at net.minecraft.src.ClientChatHandler.whileChatting(ClientChatHandler.Java:79) at org.renivivious.GuiConsole.mouseClicked(GuiConsole.java:671) at net.minecraft.src.GuiScreen.handleMouseInput(GuiScreen.java:198) at org.renivivious.GuiConsole.handleMouseInput(GuiConsole.java:356) at net.minecraft.src.GuiScreen.handleInput(GuiScreen.java:172) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1394) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:731) at net.minecraft.client.Minecraft.run(Minecraft.java:656) at java.lang.Thread.run(Unknown Source) --- END ERROR REPORT 8e0635c8 ---------- </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload