【发布时间】:2012-11-19 03:43:21
【问题描述】:
当我尝试构建这个程序时,总是出现类似“从静态上下文引用的非静态方法”的错误 我认为这是因为我可以在“main”中使用“addto”功能。那么我该如何解决这个问题呢?我需要一个公共数组列表,因为我必须在“addto”中进行计算
谢谢!
public class Calculation {
ArrayList<int[]> cal = new ArrayList<>();
public static void main(String[] args) {
System.out.println(addto(3,5));
}
String addto(int figone, int figtwo){
........do the calculations by using arraylist cal
}
}
【问题讨论】:
-
你需要一个
Calculation的实例来调用非静态方法addto