简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM