• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code Error: Need Help  RSS feed

 
Andrew McCarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, i've been working my way through a book some of you might be familiar with: "Head First Java". I've come to a code called Phrase O Matic, and am having trouble with it. I'll through the code and error message below. Hope someone can explain the problem.


(Please ignore the dots. just not sure how to make it space out right)

And the error message (again, please ignore the dots):


PhraseOMatic.java:19: cannot find symbol
symbol : variable phrase
location: class PhraseOMatic
System.out.println ("What we need is a " + phrase);
...........................................^


(Moderator edits: added code and tt tags for readability)
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,

Welcome to the Ranch!

You can use the [code] and [tt] tags (see the corresponding buttons in the editor) to improve the readability of code snippets and display fixed-width font. I have added them for you this time. Edit your post to see how the tags are used.

Look at the declaration on Line 22 and the variable on Line 24 very carefully. They need to match.

 
Andrew McCarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, but I'm pretty new to this. can you show me what you mean?
 
Andrew McCarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the spelling error, but now when i enter "javac PhraseOMatic.java" in the terminal (i'm using a mac) it doesn't do anything at all.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac is the compiler. If it doesn't appear to do anything, it's because there were no compilation errors found. you should have a *.class file.


;; this compiles your source into bytecode
$ javac PhraseOMatic.java
$ ;; all's quiet, then all's well

$ ls PhraseO*
PhraseOMatic.class PhraseOMatic.java

;; to run the program, use java, not javac
$ java PhraseOMatic

 
Andrew McCarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i realized i had only entered the compile command. It worked like a charm. thank you for your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!