If tname is null, then there is no object with an equals() method to dereference. Hence a NPE
The way to test if an object reference such as tname is null it to use ==
For example: if (tname == ...