I am trying to find duplicate words in a string array.
Here is my code for the comparison:
for ( int j = 0 ; j < wordCount ; j++)
{
It means stringArray[i] is null, i.e. your array has a null entry in it somewhere. It's possible that you have a logic error elsewhere and some elements of the array are not being set correctly.
If your array legitimately contains nulls, you have to explicitly check for this before trying to call methods on stringArray[i]:
if (stringArray[i] == null){
// Do whatever
} else if (stringArray[i].compareTo(stringArray[j]) == 0 && i!=j) {
//duplicate
duplicates++;
}