Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert String to Char

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How exactly do you do this?

I was under the impression that this:

tf = new TextField(1);
x = tf.getText();
sL = x.charAt(0) ;

converted it, but this gives an out of bounds error when compiled.

Can anyone help?
 
That's because you have to make sure that the string length is non-zero before you index into it:

if (x.length() > 0)
sL = x.charAt(0)

When you first create a text field, it has no text in it so when you call gettext on it it returns an empty string (zero length).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top