Hartmut Pfitzinger
Hartmut Pfitzinger

Reputation: 2306

NullPointerException because the Thread is null?

I received this stack strace three times now during the last months. It's only these three lines:

java.lang.NullPointerException
    at de.myapp.rec.MyThread.void run()(Unknown Source)
    at java.lang.Thread.run(Thread.java:856)

I wonder if this could mean that the method MyThread.run got null? Or are there other possible reasons for the NullPointerException?

The thread is started via

myThread = new Thread(new MyThread());
Rec.threadWritingShouldContinue = true;
myThread.start();

The source of the thread is about that:

class MyThread implements Runnable
{
    @Override
    public void run() {
        while ( Rec.threadWritingShouldContinue ) {
            int bufferSize;

            /* Do some stuff with local variables
               ...
             */
            try {
                MyMain.fileIDwrite.write(Rec.bigBuffer, Rec.bigBufByteWritePtr, bufferSize);
            } catch ( IOException e ) {
                Rec.threadWritingShouldContinue = false;
            }
        }
    }
}

Compiling with debug information wont help as it can last weeks to see it again.

Upvotes: 0

Views: 727

Answers (1)

user207421
user207421

Reputation: 310893

I wonder if this could mean that the method MyThread.run is null?

No. Methods cannot be null.

Or are there other possible reasons for the NullPointerException?

There is only one possible reason. The code dereferenced a null pointer.

Upvotes: 1

Related Questions