Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

non-static method cannot ge referenced from a static context

 
Carrie Davis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am hoping that someone can take a look at what I have and help me...

public static TestClass get(HttpServletRequest httpservletrequest)
throws TestException
{
String s = getSiteName(httpservletrequest);
TestClass testsite = null;
String as[] = getSiteList();
for(int i = 0; i < as.length; i++)
if(as[i].equals(s))
testsite = get(s);

if(testsite.getRealPath() == null)
{
String s1 = testproperties.getValue("kAssetsURL");
testsite.setRealPath(ServletContext.getRealPath(s1));
}

public void setRealPath(String s)
{
mRealPath = s;
}

This is the error that I get:
non-static method getRealPath cannot be referenced from a static context.
[ November 17, 2004: Message edited by: Carrie Davis ]
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your testsite.get() method will return a class, not an object (instance of a class). You can't call a non-static (instance) method for a class. You can either change the get method to a static method, or instantiate an object (using new) to access it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic