Are you sure that the objects in your class array are Classes? Does range return a single random integer in the specified range?

If both of those are true, it should work.

I suspect you have something other than classes in your array (such as String), causing objClass to be null.