Help regarding Compilation of Java classes.

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

Sadia in Chicago, Illinois

81 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

79 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

» Sign in or create an account to comment on this topic.