Hi, You are indeed trying to assign an array of Strings to a single String reference. When you provide an index into an array you are dereferencing it. What I mean by this is;
The variable firstname itself is as you declared it, is an array of String references, however, when you index your variable with firstname [i], you are actually referencing the single String reference that resides in the array at index i. Declaring it as a multi-dimension array will solve this. For example; String [][][] stringArray3 = new String[3][3][3]; dereferencing this once will give you a String [][] type String [][] stringArray2 = stringArray3[0]; You can further dereference this to give a String [] type String [] stringArray = stringArray2[0] or String [] stringArray = stringArray3[0][0] would do the same in a single step And once more to obtain a single String reference String string = StringArray[0]; Hope this helps Michael On Jan 19, 9:44 am, hyde <[email protected]> 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 -~----------~----~----~----~------~----~------~--~---
