Character array question

i have been working on this for the past 20 minutes or so and can not figure this out. i want to create a character array of 5 elements. and create a JOptionPane to ask the user to enter the characters.

the problem i am having is that the error message says i need char instead of string. i do not know how to convert a string to a char.

this is what i have

char[] charArray =newchar[5];

for(int x = 0; x < charArray.length; x++)

charArray[x] = JOptionPane.showInputDialog("Please enter a character:" );

[736 byte] By [ChipWhitleya] at [2007-11-26 18:21:29]
# 1
All the show...Dialog() methods return a String. You need to somehow convert that String to a char, try this:charArray[x] = JOptionPane.showInputDialog("Please enter a character:" ).charAt(0);
CaptainMorgan08a at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...
# 2

I don't do GUIs, and since you didn't paste the error message, this is only a guess, but I would imagine that showInputDialog returns a String. A String is NOT a char[], nor is it a char.

It's not clear what exactly you're trying to do. Either use String's charAt method to get the char you want from the String, or use its toCharArray (or something like that) method to convert the String into an array of characters and get the one you want after that.

Note taht what you're trying to do now will display 5 dialogs (since charArray.lengh is 5).

jverda at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...
# 3
Would it be more pleasant for the long-suffering user to enter the entire string, then simply have you program take the characters from the string?
DrLaszloJamfa at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...
# 4
> I don't do GUIsAs in, I don't do windows?
DrLaszloJamfa at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...
# 5
thank you guys, the code Captain Morgan gave me works.
ChipWhitleya at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...
# 6
> thank you guys, the code Captain Morgan gave me works.Until the user presses the cancel button, or types nothing before pressing Okay :-)
DrLaszloJamfa at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...
# 7
> > thank you guys, the code Captain Morgan gave me> works.> > Until the user presses the cancel button, or types> nothing before pressing Okay :-)Pffff, like that's gonna happen.
hunter9000a at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...
# 8
> > I don't do GUIs> > As in, I don't do windows?I've heard he has an affinity for goats though ;)
floundera at 2007-7-9 5:55:21 > top of Java-index,Java Essentials,New To Java...