weird thing with tread
in
Programming Questions
•
1 year ago
I got a class that extends Thread
the start looks as follow:
- void start(String fileName) {
- running = true;
- super.start();
- output = createWriter(fileName+".tsv");
- output.println(displayWidth+"\t"+displayHeight);
- startTime = startTime.now();
- pmouse = new Point();
- }
notice
pmouse = new Point();
This is a small part of run()
- void run() {
- while (running) {
- mouse = MouseInfo.getPointerInfo().getLocation();
- // write the mouse info
- if (mouse.x != pmouse.x || mouse.y != pmouse.y) {
Sometimes when starting the sketch it stops on the last line giving a nullpointerexception.
I tested with this line of code before the if statement:
- if(pmouse == null) println("pmouse null");
and sometimes it's indeed null but not all the times.
I know this can solve the problem:
- if(pmouse == null) pmouse = new Point();
But i would like to understand how it's possible that pmouse can be null.
So does someone have a clue?
1