Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Mysterious exception (NullPointerException)

$
0
0

Hi,

I am trying to get to work a simple server-client communication using Processing's Network library.

I want that my server refuses new clients past a certain amount of already connected clients.

Here is my serverEvent method :

void serverEvent(Server _S, Client _C) // is run when a client connects
{
  if(idCount > maxClients)
  {
    _S.disconnect(_C);
    println("Client "+idCount+" refused.");
    idCount ++;
  }
  else {
    S.write(_C.ip()+" "+Integer.toString(idCount));
    println("Client "+idCount+" connected.");
    idCount ++;
  }
}

The else part works fine. But when the program executes the if part, it throws this exception :

java.lang.NullPointerException
    at processing.net.Client.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:748)

However the exception is thrown outside the if brackets : I can print something after the if/else statement before the exception is thrown.

Any hint to solve this ?


Viewing all articles
Browse latest Browse all 2896

Trending Articles