【发布时间】:2014-12-17 07:35:37
【问题描述】:
我将size_list 定义为Long 的ArrayList。我已经做了import java.io.*;。不知何故,以下仍然给了我一个错误。我做的事情和我遇到的其他帖子一样。有谁出了什么问题?
ArrayList<Long> size_list = some_method();
try{
FileWriter fileWriter = new FileWriter("results.txt");
BufferedWriter out = new BufferedWriter(fileWriter);
for(int i = 0; i < size_list.size(); i++ ){
out.write(size_list.get(i));
out.newline();
}
out.close();
} catch(IOException ex){
System.out.println("Error writing to file " );
}
我收到的错误信息:
no suitable method found for write(Long)
out.write(size_list.get(i));
^
method Writer.write(int) is not applicable
(argument mismatch; Long cannot be converted to int)
method Writer.write(char[]) is not applicable
(argument mismatch; Long cannot be converted to char[])
method Writer.write(String) is not applicable
(argument mismatch; Long cannot be converted to String)
method BufferedWriter.write(int) is not applicable
(argument mismatch; Long cannot be converted to int)
SCCsAlgo.java:287: error: cannot find symbol
out.newline();
^
symbol: method newline()
location: variable out of type BufferedWriter
【问题讨论】:
-
这些错误应该在编译过程中被捕获。最好使用好的 IDE 进行编码。