Hi Frank,
Your firstname[i] should have a String, but you're trying to put
String[] into it because fullname[i].split(" ") gives back an array of
Strings.
Let's try this instead:
-----
firstname[i] = fullname[i].split(" ")[0];
-----
Cheers,
Bill
On 2009/01/18, at 18:44, hyde wrote:
>
> Hi all!
>
> I have a problem with the following coding:
>
> import javax.swing.JOptionPane;
>
> public class MyOwnJavaArray{
>
> public static void main(String[] args) {
> String [] fullname = new String [3];
> String [] firstname = new String [3];
>
> for(int i = 0; i < fullname.length; i++){
> fullname[i] = JOptionPane.showInputDialog("Please enter a
> name!");
> firstname[i] = fullname[i].split(" "); // this line is marked
> in the IDE !!!
> }
>
> }
> }
>
> The error I get is:
>
> found : java.lang.String[]
> required: java.lang.String
> firstname[i] = fullname[i].split(" ");
>
> Which side causes the problem, left or right ? Why is a String (and
> not a String[]) required, even though there is a String[] on both
> sides ?
> Any help would be appreciated :)
>
> Kind regards
>
> Frank
>
> >
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---