• 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

keep getting error cannot find symbol

 
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I keep getting errors, cannot find symbol. please see piece of my code, not sure where I am going wrong.

java:139: error: non-static method integerPrompt(String,int,int) cannot be referenced from a static context
int regNumber = integerPrompt("Enter registration number", 100, 5000);
^
Program7.java:145: error: cannot find symbol
theSubject = integerPrompt(SubjectsPrompt, 1, SubjectQty);
^
symbol: variable theSubject
location: class Program7
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carolin Sha wrote:
I keep getting errors, cannot find symbol. please see piece of my code, not sure where I am going wrong.

Program7.java:145: error: cannot find symbol
theSubject = integerPrompt(SubjectsPrompt, 1, SubjectQty);
^
symbol: variable theSubject
location: class Program7




Basically, the compiler is saying that the code, at that line, is using a variable named "theSubject". And it can't find such a variable that is in scope. If you go to that line, you will see that it is using a variable name "theSubject", and there isn't a local, instance, or static variable, with that name, that is in scope.

Henry
 
Carolin Sha
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Henry,

line 37 has the variable "theSubject" as an integer already. I do not understand, am I missing something?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carolin Sha wrote:
line 37 has the variable "theSubject" as an integer already. I do not understand, am I missing something?



Local variables are only in scope for the block/method that they are declared in. The variable in line 37 is a local variable of the main() method. It is not in scope for the promptSubjectNumber() method.

Henry
 
Carolin Sha
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I got it. getting not initialized messages now see error messages and updated code.

Program7.java:146: error: variable SubjectsPrompt might not have been initialized
theSubject = integerPrompt(SubjectsPrompt, 1, SubjectQty);
^
Program7.java:172: error: variable QtyGrades might not have been initialized
for (int i=0; i<QtyGrades; i++)
^
Program7.java:183: error: variable HomeWorkMark might not have been initialized
HomeWorkMark[i] = hw;

 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both the variables you are referring to are local to the particular method. Instance level variables are initialized implicitly with a default value but this is not same with method local variables. The compiler is asking to initialize those variables.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic