から参照することはできません、次のように私は、単純なJavaプログラムを持っている:非静的変数ファイルパスが静的文脈
public class HelloWorldPrinter {
String filepath;
public void setPath(String path){
this.filepath = path;
}
public static void main(String[] args) throws PrintException, IOException {
FileInputStream in = new FileInputStream(new File(filepath));
}
}
私は、次のエラーを取得しています:
HelloWorldPrinter.java:40: error: non-static variable filepath cannot be referenced from a static context
FileInputStream in = new FileInputStream(new File(filepath));
が、私はこれをどのように修正することができます?