I'm trying to call my createFile
method from the OpenFile
class in my main method, but I keep getting the error saying that I cannot call a non-static variable from a static context.
I did try calling OpenFile of = new OpenFile();
inside my main method, but that didn't work so I'm currently declaring OpenFile
above my main method which works fine, however every time I try to use one of OpenFile
s methods I get the same error.
I've tried prefacing a few things with static
but that just causes my IDE to show an Erroneous sym type error, which I think is caused by whatever is causing the other error.
Here is createFile
from OpenFile
:
public class OpenFile {
private Formatter file;
public void createFile() throws FileNotFoundException{
try{
file = new Formatter("test.txt");
} catch(Exception e) {
System.out.println("Error creating file.");
}
}
and here is my main method:
OpenFile of = new OpenFile();
public static void main(String[] args) {
// TODO code application logic here
of.createFile();
intro();
createAndShowRibbon();
createAndShowNormalUI();
}
Is it something to do with Formatter? I've never used it before.
Thanks.