2017-03-31 64 views
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有什么特别的需要吗?

+1

你需要使用“特殊”的关键字的签名:'新的请求(...)'。 –

回答

0

看起来您正在调用请求类的构造函数 要创建实例或调用annoymus对象,您需要使用新的运算符。 如果不是即你不调用构造函数,你需要定义一个方法与

Access-Specifier return type Request (type param1, type param2, type aram3, type param4){ 
    //handle your actions 
} 
相关问题