I am designing two threads: one has to get the name of players, and the second thread has to wait for the name being set in order to continue, but notify() all in the first
From the JavaDoc of IllegalStateException
Thrown to indicate that a thread has attempted to wait on an object's
monitor or to notify other threads waiting on an object's monitor
without owning the specified monitor.
You are trying to invoke the wait() and notifyAll() without having that object lock.
Please try what @Jon has suggested it will work.