严格来说,该异常是由于索引
ArrayList元素0的1的位置。注意从哪里开始循环索引变量
x。但是请考虑以下这一行:
ArrayList <Objects> xcoords = new ArrayList<Objects>();
xcoords指向一个新的empty
ArrayList,而不是您在Objects类中创建的那个。为了得到 那个
ArrayList,改变方法
xco类似
public ArrayList<Integer> xco() { // make sure to parameterize the ArrayList ArrayList<Integer> xcoords = new ArrayList<Integer>(); // .. add all the elements .. return xcoords;}然后,用你的
main方法
public static void main(String [] args) { // add correct arguments //.. ArrayList <Integer> xcoords = (new Objects()).xco(); for( int x = 0 ; x < xcoords.size() ; x++ ) { // start from index 0 System.out.println(xcoords.get(x)); }}


