Java - How to check what type the field is

I want to get a value of a field 'X' in Java.

I can do it via:

getItemValue('X'),

getItemValueString('X'),

getItemValueInteger('X'), etcetera

But how to know what type the field is..

Because field X is sometimes a Number and sometimes a String..

If i do: getItemValueString('X')

Then I get a nullpointerException..

I also tried:

String lineNumber = (String) docRegel.getItemValue("BuyerLineItemNum").elementAt(0);

and still a NullPointerException.

So I want to retrieve the value and always convert it to a String in my Java code. How to do this?

Maybe you can obtain the Item ("Item" Class, "getFirstItem" method) and check the value first?

Or, if you want allways a String, use the "getText" method.

Thanks !
String lineNumber = docCancel.getFirstItem("X").getText();
fixed it.