I tried calling a non-static method (sA2s) in a static method(addGenCache) and my IDE (JetBrains IntelliJ) gave the
Error:(56, 27) java: non-static method sA2s(java.lang.String[]) cannot be referenced from a static context
Upon research, i discovered i had options:
1) Calling an instance of the home class(Generator):
But the would be unhelpful giving that all the constructors for Generator are quite elaborate and i will need to use sA2s() in static context a number of times.
2) Creating a subclass:
I tried that here
public static void addGenCache(String genDetails[]){
record gen = new record("generators", true);
try {
sclass ss = new sclass();
gen.writeLine(ss.sA2s(genDetails));
} catch (IOException e) {
e.printStackTrace();
System.out.println("IO EXCEPTION CAUGHT");
}
}
public class sclass{
private String sA2s(String in[]){
//prepare input for export
}
}
But now i get this:
Error:(55, 21) java: non-static variable this cannot be referenced from a static context
Also if i try to initialize sclass as static, I get an illegal start of expression error.
Can someone please analyze code and tell me what I am doing wrong?
Also, is there an otherwise easier method to override this error?
sclassaspublic static class sclass{...}. Ifrecordis internal class, you should define it same way.