Help regarding Compilation of Java classes.

Get new comments by email
You can cancel email alerts at anytime.
Comments (2)

Sadia in Chicago, Illinois

51 months ago

Hi all,
I wanted your suggestions regarding Java classes.Actually the
program includes a static variable p of 'Parameter' type and
'p.add(getTickCount())' is called.The Method getTickCount is a
non-static method of package 'uchicago.src.sim.engine.SimModel '.Here
SimModel is an interface and getickCount()is a method.To get more
details about it ,please refer

repast.sourceforge.net/api/index.html

Now the problem is,it is showing error
"non-static method cannot be referenced by a static object"
So how am I supposed to refer the method using a static object.

I am looking forward for your suggestions.

Thank you

Sadia

- Was this comment helpful? Yes / No Reply - Report abuse

SyamMohan in Indianapolis, Indiana

50 months ago

Sadia in Chicago, Illinois said: Hi all,
I wanted your suggestions regarding Java classes.Actually the
program includes a static variable p of 'Parameter' type and
'p.add(getTickCount())' is called.The Method getTickCount is a
non-static method of package 'uchicago.src.sim.engine.SimModel '.Here
SimModel is an interface and getickCount()is a method.To get more
details about it ,please refer

repast.sourceforge.net/api/index.html

Now the problem is,it is showing error
"non-static method cannot be referenced by a static object"
So how am I supposed to refer the method using a static object.

I am looking forward for your suggestions.

Thank you

Sadia

Create an object of Class that contains the static variable p of 'Parameter' type and call the method using that object.

Example: Say the class that contains the Parameter as an attribute is ClassMain.

ClassMain objP = new ClassMain()
The method call will be objP.p.getickCount();
This might throw up a warning message that accessing static variable with object name instead of class name. I think that's fine.

- Was this comment helpful? Yes (1) / No Reply - Report abuse

Your Reply

change location - create a profile
User Name
 in Beverly Hills, California
Your Comment
Your Email Address
Enter the numbers you see in the box
CAPTCHA Image

Be Reasonable! Be Polite! Please read our Terms of Service and Forum Rules, where it notes that you are responsible for your own comments. You may post anonymously - but we reserve the right to remove inappropriate comments at any time.

RSS Feed Icon Subscribe to this discussion as an RSS feed.