• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Code Error: cannot find symbol  RSS feed

 
Siens Alot
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all and thank you for any help. I am greener then green as this is my first attempt to learn programming. I am receiving the below error on one of the examples in my test book and this is not a homework assignment. I have rewritten the code a few times and can not see what i am doing incorrectly. Any help would be greatly appreciated.

----jGRASP exec: javac -g CreateSpaServices.java

CreateSpaServices.java:15: error: cannot find symbol
service = keyboard.nextline();
^
symbol: method nextline()
location: variable keyboard of type Scanner
CreateSpaServices.java:24: error: cannot find symbol
keyboard.nextline();
^
symbol: method nextline()
location: variable keyboard of type Scanner
CreateSpaServices.java:26: error: cannot find symbol
service = keyboard.nextline();
^
symbol: method nextline()
location: variable keyboard of type Scanner
3 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.



The first class with out the main and is called by the second class follows:

The second Class with the main follows and i get the errors when i try and compile it. I thought it was do to me not importing the Scanner util but that part looks correct?


Thank you for any help you can provide.
on a side note is there a better program then jgrasp to use to code that uses intellisense?


Siens66



 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Siens, welcome to the Ranch.

Firstly, when posting code it is a good idea to use the Code button (above the editor where you typed your question) because this will add syntax highlighting and main any formatting of the code etc. I'm sure one of the moderators will be along soon to show you how to do that.

Now to your question:

Siens Alot wrote:
CreateSpaServices.java:15: error: cannot find symbol
service = keyboard.nextline();
^
symbol: method nextline()
location: variable keyboard of type Scanner
CreateSpaServices.java:24: error: cannot find symbol
keyboard.nextline();
^
symbol: method nextline()
location: variable keyboard of type Scanner
CreateSpaServices.java:26: error: cannot find symbol
service = keyboard.nextline();
^
symbol: method nextline()
location: variable keyboard of type Scanner
3 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


There compiler error there is telling you exactly what is wrong. The compiler has found the 'keyboard' variable, and it knows that it is a reference to Scanner. However it cannot find a method name nextline in that class. There is a method with a very similar name though.

You can find all of the available methods on the Scanner object in its Javadoc webpage found at: Scanner Javadoc.

Hint, Java is case sensitive so the case of the method names and variables that you type matter.
 
Siens Alot
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aye the case is what got me thank you very much i didn't realize that.

I have used virtual Studio when i was messing around with c# ia there a program like that for java that uses intellisense?

the help is very appreciated.

thank you
Siens
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there are several IDE's for Java.The IDE may get in the way while you're learning Java though because it will hide some details about how its compiling and packaging the code etc.

However if you want to use an IDE then a couple of choices are:

Netbeans, made by Oracle.

Eclipse, made by the Eclipse Foundation I believe.

IntelliJ, made by Jetbrains. (This is not free, but there may be a free version available for home use, or a trial version).

There may be a page on here somewhere discussing other options.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Beware of the method called next ine. If you use it after next something else you may get incorrect input. There is an explanation here, and a possible (nice simple )solution. I shall try adding code tags to your post, and if you have indented the code it will look much better
I shall warn you against IDEs. Intellisense is nice, but IDEs have such a steep learning curve there is a risk of your getting information overload. If you have written object‑oriented code (e.g. in C#), you may find migrating to Java® easier than other people. I shall suggest a half‑and‑half solution: this post suggest you use a different text editor, with links for suggestions about options and what I call writing backwards. Unfortunately that won't give yoiu intellisense.

I am pretty sure MJT is right about there being a free version of IntelliJ. The other two IDEs he mentions are available free of charge by default.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!