| Author |
Illegal initializer for java.lang.String
|
Sudheer Kolanu
Greenhorn
Joined: Nov 04, 2010
Posts: 13
|
|
I am doing an example given in Head First Java but it is giving me 7 errors, could not find out the reason for it. The below is the code and compiled errors, please advise.
Errors
C:\Library\Headache\Pro>javac Phrase.java
Phrase.java:5: illegal initializer for java.lang.String
String wordListOne={"Dave","Nick","Paul","Mark","John","Bill","Gil"};
^
Phrase.java:7: illegal initializer for java.lang.String
String wordListTwo={"is","was","isNot","wasNot"};
^
Phrase.java:9: illegal initializer for java.lang.String
String wordListThree={"a good boy","a good student","a good worker","a good thin
ker", "a good teacher"};
^
Phrase.java:20: array required, but java.lang.String found
String finalPhrase = wordListOne[rand1]+" "+wordListTwo[rand2]+" "+wordListTwo[r
and3];
^
Phrase.java:20: array required, but java.lang.String found
String finalPhrase = wordListOne[rand1]+" "+wordListTwo[rand2]+" "+wordListTwo[r
and3];
^
Phrase.java:20: array required, but java.lang.String found
String finalPhrase = wordListOne[rand1]+" "+wordListTwo[rand2]+" "+wordListTwo[r
and3];
^
Phrase.java:22: cannot find symbol
symbol : variable finalPharse
location: class Phrase
System.out.println("This is the Phrase "+finalPharse);
^
7 errors
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
|
You declare arrays with square brackets, []. So it's String[] not String before the String arrays.
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8566
|
|
What you are declaring is an array of String and not String.
Change to String wordListOne[]={..} or String[] wordListOne={...}
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Sudheer Kolanu
Greenhorn
Joined: Nov 04, 2010
Posts: 13
|
|
|
Thank you experts! I successfully run this program.
|
 |
 |
|
|
subject: Illegal initializer for java.lang.String
|
|
|