• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Code Error: Need Help

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 17331
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17331
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
This tiny ad is guaranteed to be gluten free.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic