• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SimpleDotCom game Issues

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
----------
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

That is not how you initialize an array.
 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic