這裏是我的代碼有問題:非靜態方法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
當方法是靜態時,你會像使用類名一樣使用它。方法的名稱 –