Question: I was tyring to test if my array is empty, but I always get a null pointer exception for some reason. I don't understand since my test actually test if the value is null. Here is the code where it gets stucks. I get the null pointer on the While loop:

```
private int findIndex(String key) {
        int index = calculateHashCode(key);
        while (table[index] != null && !table[index].getKey().equals(key)) {
            index = (index + 1) % TABLE_SIZE;
        }
        return index;
    }

```

**EDIT**

table is declared like this:

```
static HashEntry[] table;

```

Answer: 
The NullPointer Exception could be because either:

1. `table` is null, or
2. `table[index].getKey()` returns null

In case 1, the evaluation of the expression `table[index] != null` is a read of an item from the table array. This will throw a NullPointerException if table is null.

In case 2, if `table[index].getKey()` returns null, then the expression `table[index].getKey().equals(key)` is calling a method (equals) on a null object reference which results in the exception.
Your `table` isn't initialised, declare as 

```
static HashEntry[] table = new HashEntry[TABLE_SIZE];

```

so that it isn't null.

Also, if `HashEntry.getKey()` can return `null`, make sure you check for this (or just flip the equals, i.e. `!key.equals(table[index].getKey())`