Sameera0
Sameera0

Reputation: 1333

Parsing an Object into a String

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.

Upvotes: 1

Views: 235

Answers (3)

Andreas Dolk
Andreas Dolk

Reputation: 114767

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
}

Upvotes: 0

Poindexter
Poindexter

Reputation: 2425

value.toString()

Upvotes: 1

David Hedlund
David Hedlund

Reputation: 129792

String.valueOf(value);

Upvotes: 5

Related Questions