non static method cannot be referenced from static context

javax.servlet.http.HttpServletResponse

everything worked then i created a new class file and imported it into the orginal and moved the function printDatabase ( HttpServletResponse rs) to the new class and it gave the above error message

can i not use httpservlet response when going from class to class? or is there something else?

[351 byte] By [wadeeea] at [2007-11-26 18:35:22]
# 1

Since you haven't included any code in your post we can only guess, but I think the crux of the problem is that you are doing something like this:

public void f() {}

public static void g() {f();}

To fix this, rethink the code. Maybe the static method should be non-static, or the non-static method should be static, or the invocation of f() should be applied to a specific object.

DrLaszloJamfa at 2007-7-9 6:09:27 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks!I just need it to bepublic static void {}instead ofpublic void {}
wadeeea at 2007-7-9 6:09:27 > top of Java-index,Java Essentials,New To Java...
# 3

But then as pointed out, are you sure you want it static (both methods static that is)? ... To call a non-static method from a static context you need the Object reference of the non-static member/method. ...

public class AllAboutA {

private int A;

protected int getA() {

return( ++A );

}

public static void main(String[] argv) {

int a = getA(); // N/G

int a = new AllAboutA().getA(); // OK

}

}

abillconsla at 2007-7-9 6:09:27 > top of Java-index,Java Essentials,New To Java...