aspose file tools*
The moose likes Beginning Java and the fly likes  Illegal initializer for java.lang.String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Illegal initializer for java.lang.String" Watch " Illegal initializer for java.lang.String" New topic
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: 9995
    
    7

What you are declaring is an array of String and not String.
Change to String wordListOne[]={..} or String[] wordListOne={...}


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Sudheer Kolanu
Greenhorn

Joined: Nov 04, 2010
Posts: 13
Thank you experts! I successfully run this program.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal initializer for java.lang.String
 
Similar Threads
Once Over
PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...)
unclosed string literal error
PhraseOMatic syntax problem in Head First Java
The correct version of the Phrase-O-Matic (ref:Head First Java)