In a java file I'm consistently having a runtime error `Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException` at a line with a while loop and need to find a way to avoid this nullPointerException.

My current code at this line looks like this : 

```
while (b.isOnBoard(row-i, col-i) && b.getState(row-i, col-i).equals(yourcolor))
{
    count++; 
    i++;
}

```

The object `b` is basically an 8 by 8 matrix "board" for the game othello. The method `isOnBoard` will return a boolean, and the method `getState` will return either my players color, my opponents color(`yourcolor`), or `null`. I don't understand why any of these returning null though would cause a nullPointerException. 
Can anyone tell me what would be causing this error and how to fix it? Any help is greatly appreciated.