File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Unable to figure out what is stopping my compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unable to figure out what is stopping my compile" Watch "Unable to figure out what is stopping my compile" New topic
Author

Unable to figure out what is stopping my compile

Christian Staves
Greenhorn

Joined: Jul 07, 2010
Posts: 26
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.

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Hi Christian, welcome to the ranch ! Please UseCodeTags the next time you post some code.


[My Blog]
All roads lead to JavaRanch
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
You have not defined titlle, author and price in your BookTester class.
Christian Staves
Greenhorn

Joined: Jul 07, 2010
Posts: 26
I will, thank you for fixing it.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Jul 07, 2010
Posts: 26


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

Joined: Jun 01, 2010
Posts: 618
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Jul 07, 2010
Posts: 26
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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.
 
jQuery in Action, 2nd edition
 
subject: Unable to figure out what is stopping my compile