• Post Reply Bookmark Topic Watch Topic
  • New Topic

2 problems (invalid symbol  RSS feed

 
Michael Dunkley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have 2 programs. Both of these programs are unable to find symbol. Help please?


For this program the input.nextInt symbol cannot be found?

As for the second program.. Not sure if this is a little advanced but I'm using 3 separate methods.. One method is to print out messages to the user and the other 2 does area and volume calculation based on the user input

For this one the main class file cannot find Area? I've tried everything humanly possible!! Or feel as though I have
 
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
Michael Dunkley wrote:
For this program the input.nextInt symbol cannot be found?


Well, The input variable isn't a variable that is in scope for the main() method. And considering that the compiler is complaining, I will guess (since you didn't show us the code) that it isn't a static variable either.

As for the second case ... similar answer.


BTW, welcome to the ranch.

Henry
 
Michael Dunkley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Michael Dunkley wrote:
For this program the input.nextInt symbol cannot be found?


Well, The input variable isn't a variable that is in scope for the main() method. And considering that the compiler is complaining, I will guess (since you didn't show us the code) that it isn't a static variable either.

As for the second case ... similar answer.


BTW, welcome to the ranch.

Henry

I thought I inserted the code in my post?

As for the first one my thoughts did think of something alike that.. Since the area variable used in the output volume subclass is declared in the outputArea subclass and wasn't sure whether the main would accept it or not

Thanks for the welcome!!
 
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
Michael Dunkley wrote:
I thought I inserted the code in my post?

As for the first one my thoughts did think of something alike that.. Since the area variable used in the output volume subclass is declared in the outputArea subclass and wasn't sure whether the main would accept it or not


Yeah, local variables are not accessible outside of the method where it is declared.

Henry
 
Michael Dunkley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Michael Dunkley wrote:
I thought I inserted the code in my post?

As for the first one my thoughts did think of something alike that.. Since the area variable used in the output volume subclass is declared in the outputArea subclass and wasn't sure whether the main would accept it or not


Yeah, local variables are not accessible outside of the method where it is declared.

Henry


Thanks!!

Absolute life saver.. Was under the impression I'd end up crying myself to sleep. I ended up combining the methods for volume and area calculation
finally got the program working so it now outputs values.. Just incorrect ones for volume!
 
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
Michael Dunkley wrote:
Absolute life saver.. Was under the impression I'd end up crying myself to sleep. I ended up combining the methods for volume and area calculation
finally got the program working so it now outputs values.. Just incorrect ones for volume!


Not sure how this is a life saver. You really should understand the scopes of the different variable types (local, instance, static), and how to pass values between methods.

Merging methods to avoid this can only go so far, and quite frankly, in the extreme, will end up having everything in one big main() method. This is not a good thing.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!