java静态方法返回值问题

KueenLau 2016-04-12 07:28:01
public static ArrayList<Coordinate> createTrajectory(String filename) {
File file = new File(filename);
ArrayList<Coordinate> tra = new ArrayList<Coordinate>();
if(file.exists()) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String str;
String[] line;
Coordinate c;

while(in.readLine() != null) {
str = in.readLine();
line = str.split(",");
Double x = Double.parseDouble(line[2]);
Double y = Double.parseDouble(line[3]);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date t = sdf.parse(line[1]);
c = new Coordinate();
c.setX(x);
c.setY(y);
c.setTime(t);
tra.add(c);
}

in.close();
} catch (IOException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
return tra;
}

为什么报错:Cannot make a static reference to the non-static type Coordinate?????????
...全文
564 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
静态方法可以直接用类名调用,
  • 打赏
  • 举报
回复
一个静态方法,不能返回一个非静态的东西,是这么理解吗

23,402

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧