aspose file tools*
The moose likes Beginning Java and the fly likes non-static method cannot ge referenced from a static context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "non-static method cannot ge referenced from a static context" Watch "non-static method cannot ge referenced from a static context" New topic
Author

non-static method cannot ge referenced from a static context

Carrie Davis
Greenhorn

Joined: Mar 23, 2004
Posts: 4
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

Joined: Jul 30, 2003
Posts: 804
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.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: non-static method cannot ge referenced from a static context