• 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

Arrays and Methods

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys, thanks for always being so helpful, even to the silliest of questions I ask. I truly appreciate the ability to have access to such a fantastic community.

So I'm trying to make a real simple Pokedex. Right now, I'm just doing a test entry. I have all the variables and such assigned and ready to go, and it compiles fine. But the moment I start to add a method to put it all together, everything falls apart. This is the code as it stands:



And then I get this error back:




I've tried removing public static void main (String[]]args) and it's brackets, which leads to a huuuuge error list.

So I honestly can't figure it out. I'm following along with Headstart Java if aybody is wondering, just finished chapter 5. This is just a project I'm doing because arrays are still really confusing. So by the time I get this figured out and completed, I should have a pretty darn good understanding of them.

Anyways, any help would be much appreciated, and I can supply any more needed information!
 
Ranch Hand
Posts: 116
2
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you did not close your main() method.

Since you are defining a new method on line 24, you should close your main() method on line 23 with a }.

Also, remove the semi-colon at the end of line 24 since it's a method, not a statement. Also you will need to put the text output on line 24 in a

Let me know if you have any questions about these changes.
 
Kyle Fraser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, so that made sense, I can't believe I forgot to put System.out.println. That was silly. =p

I changed my code to this:



And now I'm getting the following error:



And so on and so forth for every variable.

I don't know too much about the errors yet, and a google search informs me that symbol errors can mean a great number of things.

I appreciate the assistance I've been given, and I would greatly appreciate any more!
 
Scott Winterbourne
Ranch Hand
Posts: 116
2
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This error is because your variables such as "name" are declared inside the main() method giving them method scope only. They will not be visible to anything outside of that method, meaining when creating a new object, you will not be able to reference them directly on that new object.

You will need to move the variable declarations outside of the main() method (above it on line 2 between the class definition and main() method). Might be a good idea to make them public for now also (i.e. public String name;)
 
Kyle Fraser
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that compiled perfectly! Thanks so much!

Just for further understanding though, by this:

This error is because your variables such as "name" are declared inside the main() method giving them method scope only.



Do you mean that variables defined inside main can only be used inside main? Because if so, I actually didn't know that, and would explain a ton of my problems.
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any variable that you declare within any method is local to the method, meaning that the variable can only be used inside the method and is not visible outside of that method.

Carrying it a bit further for more information, a variable's scope is local to the block in which it is declared which is between the {} brackets. Once you leave that block you can no longer call on that variable.

Example:

 
reply
    Bookmark Topic Watch Topic
  • New Topic