这里是我的代码有问题:非静态方法openInputFile(字符串)不能从静态CONTEX的Java引用
public File openInputFile(Scanner kb)
{
if(kb == null)
{
throw new RuntimeException("ERROR! Scanner Not Detected.");
}
System.out.print("Enter Name of File: ");
String fn = kb.nextLine();
File inf = FileUtil.openInputFile(fn);
return inf;
}
我收到以下错误:
FileUtil.java:33: error: non-static method openInputFile(String) cannot be referenced from a static context
File inf = FileUtil.openInputFile(fn);
^
没有什么静态,所以我不知道为什么我得到这个错误。谁能帮忙?
你用它告诉编译器它是静态的方式实例来调用它。 –
你能详细说一下吗? – user210394
当方法是静态时,你会像使用类名一样使用它。方法的名称 –