Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

accessing a static variable froma different class

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm kind of new to this topic, so please bear with me.
Ok, i have two classes within the same program
1-project
2-called
the program's too large to post, so i'll post the relevant section


now when i try to compile, i get an illegal start of type exception at the place i've commented. i dunno if its something to do with the static variable, beacause when i try to access project.index, it works perfectly.
Any ideas? its part of a larger program, but resolving this would make the whole thing more efficient.
thanks
 
vedant basu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, i forgot to mention, both index and option are static variables in class project.
 
Marshal
Posts: 76486
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely you get the compiler error on line 10? That is where you had = instead of ==, which is the error I could see. You are also writing statements inside the class, which ought to be inside a method.
Please use code tags (not size); I have changed them and you can see how much better it looks. It would have looked even better with indentation. Correct indentation would have made the error about inside a method obvious to you.

And welcome to the Ranch
 
vedant basu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
uh yeah, i'm sorry, that was something i missed, and thanks for the update on the code tag.
but no, i can't get that if statement to work. how exactly do you access a static variable, because variable 'index' works perfectly!
thanks
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vedant basu wrote:uh yeah, i'm sorry, that was something i missed,


Was that referring to the '=' instead of '==' or

Campbell Ritchie wrote:You are also writing statements inside the class, which ought to be inside a method.

 
vedant basu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was talking about the'='.
so the problem is the 'if' statement? it should be in a 'main' method?
 
vedant basu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a main function won't let me access variable 'c' in other methods, will it?
 
Campbell Ritchie
Marshal
Posts: 76486
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to revise methods and classes. No, it ought not to be in the main method. That should have one statement, something along these lines:That if statement ought to be in another method. I don’t know what it ought to be called.
Also, return is a keyword, so must not be used as the name of a method, so the compiler won’t like return();
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic