• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Variable problem

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have the following code. i import my class (Restaurant+Review) but when i try to print the variable i get a "cannot find symbol error code" which im guessing is because the following code doesnt have access to the variables even though the class is imported
 
Rancher
Posts: 4885
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

get a "cannot find symbol error code"


Please copy the full text of the error message and paste it here. It has important info about the error.

What variable in what statement is that error about?
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

get a "cannot find symbol error code"


Please copy the full text of the error message and paste it here. It has important info about the error.

What variable in what statement is that error about?



The error code is "cannot find symbol Symbol: Variable name Location class DAOImpl".. the error code is both on the name and review variables
 
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you importing classes from the same package? Or do you have two packages with the same name, which is a sure‑fire recipe for confusion? Or are you getting problems because there are variables which you haven't declared? If you don't give us the full details of what is going on, how can we help you?
Why have you called that class DAOImpl? It isn't a DAO class.
Why have you made that method static? If you are only trying out code, use JShell instead. See these links: 1 2.
Don't call close(). Read this tutorial for the correct way to close your writers.
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Georgios Adamidis wrote:. . . cannot find symbol Symbol: Variable name Location class DAOImpl. . . .

And a few minutes ago, I wrote:. . . variables which you haven't declared? . . .

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Importing a class doesn't give you access to its data, unless that data is static.
If I remember your other threads correctly neither of those two classes has static data (which is almost certainly the correct thing).

What exactly are you hoping to do with this class?
Is it the usingPrintWriter method (perhaps) supposed to take an instance of Restaurant and Review as parameters?
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect, from OP's other threa‍d, that name and review are Strings.
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Importing a class doesn't give you access to its data, unless that data is static.
If I remember your other threads correctly neither of those two classes has static data (which is almost certainly the correct thing).

What exactly are you hoping to do with this class?
Is it the usingPrintWriter method (perhaps) supposed to take an instance of Restaurant and Review as parameters?


this class is meant to write the variables in a text file and store them
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I suspect, from OP's other threa‍d, that name and review are Strings.


indeed they are kind sir
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a code for a class named DAOImpl which is meant to write variables in a text file.. my code is as follows

I get the error code on the printWriter.println(name ); line even though i have imported my class where the variable is declared. Any help is much appreciated
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You appear to be asking the same question twice. Please look at this link. I think the two thre‍ads should be combined into one.

The fact that there is a name variable in another class does not mean it is accessible from inside your current class.
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Writing plain simple name implies you are using the variable from your current class.
 
And inside of my fortune cookie was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic