• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class or instance variable  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am baffled about a technical issue that the compiler refuses to pass through. "private Product product;" I have been trying to use 'get''and 'set' methods without success! I have googled left right and centre hoping for a lead on this question. As a newbie any pointers that can help with the compiler are welcome thanks.
 
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code? It's hard to tell what the problem is without seeing the code
Is the class Product in a different package than the class in which you declare it? If so, you might just miss an import statement.
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Since the bit of code that you gave has nothing syntactically wrong with it, it's probably as Dennis said, you're probably missing an import statement. That's just an educated guess though; please TellTheDetails (←click on that link) so we can give a more definitive answer.
 
John Hewitson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the delay, I was waiting for emails from this site! I rather thought the folders on 'Tomcat' were fixed for this project, 'app01c' folders have been successful! So there is the following "/webapps/app02a/WEB-INF/classes/app02a/httpsession". The 'Product' class file is in that folder! However the source file is in a 'Java' depot folder. As you have indicated the 'compiler' may be looking for a file somewhere! I am trying to attach a file herewith. Thanks for the replies.
ShoppingItem.jpg
[Thumbnail for ShoppingItem.jpg]
 
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the compiler error you're getting?

And when posting code it's best to post it directly into the forum rather than posting images. Use the Code tags (there's a button at the top with the other formatting options).
 
John Hewitson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How to copy off the terminal would be nice to know thanks.
 
John Hewitson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Hewitson wrote:How to copy off the terminal would be nice to know thanks.


If you mean the Windows command line: right-click on the icon at the top left corner of its window and you'll get a menu where you can mark and copy text from the window.
 
John Hewitson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks for the pointers, appreciated!!
 
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to import Product class in your shoppingitem.java before you use Product.

As someone already mentioned and I can also see in your snap shot you haven't imported that.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I read everything in the thread carefully, it looks to me like you think the Product class is in the package app02a.httpsession, along with the ShoppingItem class. So if you compile ShoppingItem and the compiler can't find Product.class in that package, that either means you didn't compile Product yet, or else your classpath isn't set up correctly. You shouldn't have to import Product if it's in the same package as ShoppingItem.
 
John Hewitson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have tried to import 'Product' into the ShoppingItem.java file. There is no ShoppingItem.class file! The compiler is complaining ok
 
John Hewitson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That old chestnut...... the classpath! ".;C:\tomcat8.0\lib\servlet-api.jar;" is the classpath I use and it is successful on the whole! Any advice is welcome ok
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!