0
我目前正在編寫一個代碼,它從文件中獲取信息,然後使用基於對象Request
(我已經在另一個java文件中編寫)填充數組信息在文件中。這是我在我的main
方法使用參數化構造函數添加到ArrayList
Scanner userIn = new Scanner(System.in);
System.out.println("Please input the file name that you would like to be read into reqMover");
String thisFile = userIn.next();
FileReader inReader = new FileReader(thisFile);
Scanner inFile = new Scanner(inReader);
ArrayList<Request> newReq = new ArrayList<Request>();
do{
newReq.add(Request(inFile.nextInt(), inFile.nextInt(),
inFile.nextInt(), inFile.nextInt()));
inFile.nextLine();
}while(inFile.hasNextLine());
此代碼駐留在被稱爲reqMover
一個java文件至今。我遇到的這個問題是,編譯器告訴我「方法Request(int, int, int, int)
對於類型reqMover
未定義」,儘管該方法是我在其他類中創建的構造函數。使用這個構造函數加載ArrayList
有什麼特別的需要嗎?
你需要使用「特殊」的關鍵字的簽名:'新的請求(...)'。 –