• 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

Unable to figure out what is stopping my compile

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, So my class is working and compiling, but I cant seem to fix the error in my tester. Im taking java at school and I've been working on this all day since 7am, a good 5-7hours and my teachers not really responding. Im not asking to be given the answer, but Im just tired of this program at this point. I've googled and googled and nothing, so if anyone could please help me by showing me where I messed up or telling me where to look. I would be Sooooooooooo Thankful.

I mean Im close right? I just cant seem to figure it out.
oh yeah my error is, but before I added the title,author,price to the new constructor, it keep erroring at new Book().


BookTester.java:15: cannot find symbol
symbol : variable title
location: class BookTester
Book book = new Book (title,author,price);
^
BookTester.java:15: cannot find symbol
symbol : variable author
location: class BookTester
Book book = new Book (title,author,price);
^
BookTester.java:15: cannot find symbol
symbol : variable price
location: class BookTester
Book book = new Book (title,author,price);
^
3 errors


Solved by moving Book book = new Book(); to after the reader lines had been stored that way the book had a reason to exist.

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christian, welcome to the ranch ! Please UseCodeTags the next time you post some code.
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not defined titlle, author and price in your BookTester class.
 
Christian Staves
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will, thank you for fixing it.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I've been working on this all day since 7am, a good 5-7hours


You need a break

Look at the error message carefully :

BookTester.java:15: cannot find symbol
symbol : variable title
location: class BookTester
Book book = new Book (title,author,price);

This means that the compiler cannot find any declaration of the variable called "title", at the 15th line of BookTester.java. If you look at that line, you'll see that neither title, author, nor price, are declared. If you want to instantiate a Book without setting its instance variables, maybe you should declared a constructor without arguments (public Book() {}) and instantiate it in your tester class (Book book = new Book ();)
 
Christian Staves
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I had it setup as Book book = new Book(); and it kept erroring and one of my class mates told me to put title,author,price in the constructor.
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I thought that by doing String title = reader.nextLine() that was defining it.


You are correct. But you must define them before you use them. Move the new Book(...) line down after you define those variables.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, you don't need to instanciate the book at the beginning. You can do it after reading all values. So you should move Book book = new Book (title,author,price); after having read the price.
 
Christian Staves
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tom Reilly wrote:

I thought that by doing String title = reader.nextLine() that was defining it.


You are correct. But you must define them before you use them. Move the new Book(...) line down after you define those variables.




RAGE...................................so by simply moving my Book book = new Book(); under the title.reader instances, everything now compile and it runs like achamp.....



I'm both happy and angry , happy that my code was correct and thats why I couldnt find a flaw, and angry that I didnt know to put it below everything.

Thank you all for your help I am ever so thankful.

I'll be back tomorrow when I get stuck on something else dumb....

But really thank you all for the quick replys and helpful attitudes.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may be worthwhile reading about scope of variables.

But you shouldn't work for hours and hours. You should never go more than 5 minutes without compiling your work. That way you find the errors so much sooner.
reply
    Bookmark Topic Watch Topic
  • New Topic