I am making a UDP server which receives a string, I have to modify that string, but I can't seem to figure out how to forward the string to the class that is supposed to handle the string, I get the following exception:
"can't create handler inside thread that has not called looper.prepare()"
I have little experience with android and can't figure out how to solve the problem, and none of the other questions about this seemed to give me the answer.
public class Server implements Runnable {
@Override
public void run() {
while(!start)
{
//do nothing
}
try {
InetAddress serverAddr = InetAddress.getByName(SERVERIP);
//updateTrack("\nServer: Start connecting \n");
DatagramSocket socket = new DatagramSocket(SERVERPORT, serverAddr);
byte[] serverBuf = new byte[1064];
DatagramPacket packet = new DatagramPacket(serverBuf, serverBuf.length);
//updateTrack("Server: Receiving \n");
socket.receive(packet);
int realSize = packet.getLength();
byte[] RealServerBuf = new byte[realSize];
System.arraycopy (serverBuf, 0, RealServerBuf, 0, realSize);
recived = new String(RealServerBuf);
//updateTrack("Server: " + recived + "\n");
StringHandler stringHandler = new StringHandler();
stringHandler.StringSplitter(recived);
updateTrack("Server: Succeed\n");
} catch (Exception e) {
updateTrack("Server: Error\n" + e);
}
}
}
Tthe problem has something to do with how I instantiate the StringHandler.class and it not being connected with the UI-thread, but I can't figure out how to do it.