• Post Reply Bookmark Topic Watch Topic
  • New Topic

SimpleDotCom game Issues  RSS feed

 
Hozi Surat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am going through the Head First Java book and I am working with the SimpleDotCom game. Everytime I compile my code I keep getting the following three errors and I can't figure out what my issues are. Please help. Thanks.

my SimpleDotCom class


my GameHelper class



and my Game class


here are my errors



int[] locations=(randomNum,randomNum+1,randomNum+2);
^
Syntax error on token "=", Name expected after this token
----------
----------

inputLine = is.readLine();
^^^^^^^^^^^^^
Type mismatch: cannot convert from java.lang.String to com.sun.org.apache.xpath.internal.operations.String
----------

if(inputLine.length()==0) return null;
^^^^^^
The method length() is undefined for the type String
----------
 
Johan Fourie
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

That is not how you initialize an array.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hozi Surat wrote:
int[] locations=(randomNum,randomNum+1,randomNum+2);
^
Syntax error on token "=", Name expected after this token


Your parenthesis should be curly brackets.

Hozi Surat wrote:
inputLine = is.readLine();
^^^^^^^^^^^^^
Type mismatch: cannot convert from java.lang.String to com.sun.org.apache.xpath.internal.operations.String

--------

if(inputLine.length()==0) return null;
^^^^^^
The method length() is undefined for the type String


It seems you are using the wrong String class. Do you happen to have an import at the top of your class that looks something like:



If so, remove it.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

One of the naughty habits of Eclipse is providing a long list of potential imports; it is very easy to click on the wrong one. you should not import String at all; it is in the java.lang package.
 
Hozi Surat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that was it the {} and the import statement.


Also thank you for the info about the import.

I have a question when eclipse gives me more than 1 option for import how do i go about determining+++ which one to use?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!