The countNonZero() method can process single channel images only, but it seems your grayMat isn't.
I suspect it keep a draw-able gray-scale image, i.e. of type CV_8UC4 and the channel ## 0,1,2 have the same values and the channel #3 is filled with 255 value.
I suggest you extract say the 1st channel and call the countNonZero() method:
  Mat m = new Mat();