0

I am currently having some trouble on display errors. When an error occurs, it is called from a method in another class.

public void foomethod(Foo foo, Fuu fuu) {
    if(foo.getMethod() == 0) { 
        if(engine.placeMethod(foo, fuu) == true) {
            foo_view.removeCurrentError();
            engine.rollFoo(foo, frame.getInitialDelay(), frame.getFinalDelay(), frame.getDelayIncrement());
        }
        else {
            foo.placeMethod(0);
        }
    }
    else { 
        foo_view.displayCurrentError("Foo has already placed a method"); 
    }   
}

And this is the thread

@Override
public void actionPerformed(ActionEvent e) {
    new Thread() {
        @Override
        public void run() {
            try {
                int fuu = Integer.parseInt(frame.getGameView().getFooView().getMethod());
                Foo bet_foo = frame.getGameView().getFooView().getFoo();
                foomethod(bet_foo, fuu);
            } catch (NumberFormatException excpetion) {
                System.err.println("fuu is not an integer");
            }           
        }
    }.start();  
}

The error it displays is

Exception in thread "Thread-3" java.lang.NullPointerException
at controller.FooListener.rollFooDice(FooListener.java:31) <-- this is foo_view.removeCurrentError();
at controller.FooListener$1.run(FooListener.java:57) <-- this is .start();

The problem is when I call foo_view.removeCurrentError(); the error shows up and the error display shows the same exception.

Jay Lee
  • 23
  • 4
  • Those don't help the OP solve their issue. – Rohlex32 May 24 '18 at 17:05
  • @OP Please display the `controller.FooListener.rollFooDice(` method for us please. – Rohlex32 May 24 '18 at 17:06
  • @Rohlex32 Forgot to edit that, rollFooDice is foomethod() – Jay Lee May 24 '18 at 17:08
  • 1
    @Lutzi may i ask why this question is a possible duplicate? – Jay Lee May 24 '18 at 17:13
  • what OP is stands for? – oreh May 24 '18 at 17:13
  • 1
    Where are you setting `foo_view`? – Peter Lawrey May 24 '18 at 17:35
  • 1
    @oreh It’s Original Poster, i.e. the person who asked the question – achAmháin May 24 '18 at 17:37
  • 1
    @Rohlex32, Helping the OP solve their problem should be a secondary concern here. We want the OP to _understand_ the problem. Answers on the "What is a NullPointerException..." question provide ideas for how to debug an NPE (i.e., how to find out which pointer is null and why). – Solomon Slow May 24 '18 at 20:24
  • @Jay Lee, he just answers exactly what I would answer. If this question arise "Why do I have a null pointer exception", it means you didn't understand this exception and how to fix it. We can't answer all NPE, posters have to search a bit for their errors and to understand the problem. – Lutzi May 24 '18 at 20:46

1 Answers1

0

foo.getMethod() <- this method

foo_view.removeCurrentError(); <- This line
....^ This variable is still null at the point when this line of code is being exectued.

Rohlex32
  • 120
  • 9