I created a client/server program where the server sends a packet to the client which has a randomly picked string from an array. But when ever I run the server and then the client which send data about it's byte array the server after receiving the packet throws an exception which looks like this:
Exception in thread "SDServerThread" java.lang.NullPointerException
at SDServerThread.run(SDServerThread.java:56)
This exception points to this line of code:
buf = GetText.getBytes();
The buf is a byte array list:
byte[] buf = new byte[256];
GetText is a string which calls a method to pick a random string.:
String GetText = getText();
The code starting from byte[] buf = new byte[256]; to buf = GetText.getBytes(); looks like this:
byte[] buf = new byte[256];
DatagramPacket packet = null;
packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
System.out.println("packet received");
textArea.append("packet received\n");
String GetText = getText();
buf = GetText.getBytes();
I haven't tried a lot because i can't find any fixes relating to my kind of problem.
Thanks in advance for the help.