mardi 7 avril 2015

ServerSocket accept throws nullpointerexception

Vote count:


I am having a problem with a client server app I am working on, for some reason the ServerSocket class accept message is throwing a NullPointerException when a client attempts to connect to it.

Here is the class responsible for the server:

public class DeviceNameServer implements Runnable {
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(Utils.SERVERPORTDEVICENAME);
while (!Thread.currentThread().isInterrupted()) {
Socket clientSocket = serverSocket.accept();
Thread t = new Thread(new DeviceNameRunner(clientSocket, new DefaultDeviceIdentifier()));
} catch (IOException e) {
Log.e("CalpolException", e.getLocalizedMessage());

This is called by an Activity

nameServerThread = new Thread(new DeviceNameServer());

nameServerThread is a member of the Activity

This is the code responsible for connecting to the server:

Socket socket = new Socket();

try {
socket.connect(new InetSocketAddress(serverIp, Utils.SERVERPORTDEVICENAME), 500);

InputStream is = socket.getInputStream();
while (socket.isConnected()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder out = new StringBuilder();


} catch (IOException e) {

As soon as this executes the serverSocket.accept() message throws a NullPointerException

Has anyone seen this before?

asked 13 secs ago



ServerSocket accept throws nullpointerexception

Aucun commentaire:

Enregistrer un commentaire