• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using a variable from a static extended class in a non-static  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a someway special question, because I am using jmonkeyEngine.

But the topic is simple:

I have 2 classes:



as the main class and a second class for the chips:



My problem is: I can't access getAM() from the first in the second class.
If you know why I would be glad for an answer.
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method getAM is a non-static method, but you're calligraphy calling it as if it is a static method. Static methods can (and should) be called using the class name (i.e ClassName.methodName()). Non-static methods need to be called via an object of the class.

You need to either make the method static or create an instance of the class. Which option you pick will depend on exactly what the method is returning, but in general favour non-static methods.
 
Marshal
Posts: 56600
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calligraphy?

You must have a good word completer Maybe you meant “calling”.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
joh wra wrote:My problem is: I can't access getAM() from the first in the second class.
If you know why I would be glad for an answer.

I think Mike's basically covered it ("calligraphy" notwithstanding ).

However, I wonder why you would think that Spielstein.getAM() would even qualify as "access[ing] getAM() from the first in the second class", since you're using the second class's name to call it.

My advice:
1. Do that assignment inside your constructor, rather than directly on the field; and follow Mike's advice.
2. (Just a tip; not actually required):
this.stone = assetManager.loadModel("Models/stone/stone.j3o");
will save you quite a bit of typing.

HIH

Winston
 
joh wra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advices. I am now passing the assetManager in the Constructor and everything's fine.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Calligraphy?

You must have a good word completer Maybe you meant “calling”.


See this is what I get for posting from my phone! I normally spot it. Thankfully this wasn't too embarrassing a substitution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!