• Post Reply Bookmark Topic Watch Topic
  • New Topic

keep getting error cannot find symbol  RSS feed

 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • 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
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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: 68
1
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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: 68
1
  • Mark post as helpful
  • send pies
  • 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;

 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!