[Solved] new Thread(runnable, name) return null [closed]


Without more information the following is really only speculation. Please in the future show more details and explain what you have done to debug the problem.

after new Thread, thread is still null and i don’t know why please help.

It is not possible for a constructor to return a null so something else is going on.

Thread thread = null;
thread = new Thread(this, "game");
// thread is guaranteed to be non-null here

Maybe you are sharing the thread field between two threads? For example, maybe your main thread starts the background thread and the UI thread is trying to read it? In that case you should make thread to be volatile to be shared between threads.

volatile Thread thread = null;

If it is already volatile then you you are dealing with a different instance of the thread field. Maybe the thread field should be marked as static?

5

solved new Thread(runnable, name) return null [closed]