From efbf5ad6c8a8775fbe704695a13b378e97ced5d7 Mon Sep 17 00:00:00 2001 From: Alena Bandarovich Date: Wed, 7 Feb 2024 19:27:57 +0100 Subject: [PATCH] Check connection to server before closing --- src/main/java/ChatClient.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 93731f3..851ef84 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -61,10 +61,12 @@ public class ChatClient extends JFrame implements KeyListener { } catch (IOException e) { JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); } finally { - try { - connectionToServer.close(); - } catch (IOException e) { - e.printStackTrace(); + if (null != connectionToServer) { + try { + connectionToServer.close(); + } catch (IOException e) { + e.printStackTrace(); + } } try {