-2
public  boolean end(Cat cat, Mouse mouse){
    String d="drowned";
    String e="escaped";

    String s=mouse.checkMoblity();
    System.out.println(s);

// error next line
    if(s.equals(d)){
        return true;
    }

    else if(s.equals(e)){
        return true;
    }

    else if(mouse.getLocation()==cat.getLocation()){
        return true;
    }

    else return false;
}

This is part of my code. When I tried to debug it, it gave me an error on the equals method. I don't know how to fix it.

When I compile..

nullException in thread "main" java.lang.NullPointerException
at Chase.end(Chase.java:93)
at Chase.playGame(Chase.java:23)
at Chase.main(Chase.java:115)
roarster
  • 3,785
  • 1
  • 20
  • 37
Allen
  • 59
  • 9
  • 2
    Please include the error message in your question and create a [MCVE](http://stackoverflow.com/help/mcve). – Turing85 May 21 '16 at 11:13
  • 2
    Welcome to Stack Overflow. Unfortunately "it gave me a error" isn't nearly enough information... was the error at compile-time or execution time? What was the error? Please provide a [mcve]. – Jon Skeet May 21 '16 at 11:13
  • I cannot run the program. And when i debug it, the erorr points to the line that I marked – Allen May 21 '16 at 11:18
  • Most porbably, the call to `mouse.checkMobility()` returns `null` and therefore `s.equals(...)` results in a `NullPointerException`. This, it is a duplicate of [this question](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it). – Turing85 May 21 '16 at 11:19
  • Isn't this a followup of your [other question](http://stackoverflow.com/questions/37361226/java-match-point)? The one you asked an hour ago? You shouldn't post multiple questions regarding the same problem. (For others: the issue in the other question was that `checkMobility` was returning `null`, so @Turing85 you are completely right.) – Arc676 May 21 '16 at 11:20
  • Yes. that is it. mouse.checkMobility() did always return null. I don't know why and I am fixing it. – Allen May 21 '16 at 11:21
  • Oh i am sorry. Becasue I just think they are different types of question. – Allen May 21 '16 at 11:22

1 Answers1

2

mouse.checkMoblity() returns null.

zeromem
  • 332
  • 2
  • 11