views:

90

answers:

3

Hi there I am looking to parse an Object I have into a String so that I can enter it's value into a textfield. Here is a little snippet.

TFname is the name of the textfield

Object value = list.getSelectedValues();
TFname.setText(parseObject(value)); //-- Here I pick up an error

Where I pick up the error, I know it's because this isn't how you parse an object but I was wondering if anyone knew how I would go about doing it properly.

If anyone could help I would be very grateful.

+5  A: 
String.valueOf(value);
David Hedlund
+1 for handling null.
Russ Hayward
+1  A: 
value.toString()
Poindexter
In general I would recommend doing String.valueOf(value) as that won't NPE.
Paul Wagland
A: 

list.getSelectedValues() returns an Array of Objects. Try this code, if it fails, error details wouldbe helpful

Object[] value = list.getSelectedValues();
fName.setText(parseObject(value)); //-- Here I pick up an error

Note: I assume, there is this method in the same class:

String parseObject(Object[] values) {
  // method body
}
Andreas_D