我正在尝试建立Earthquake对象的ArrayList,但是Java抱怨看不见。

我的代码:

import java.io.*;
import java.util.Arrays.*;

public class ObservatoryTest {
    private ArrayList <Earthquakes> listOfEarthquakes; //This list is not visible
    Earthquakes Quake1 = new Earthquakes(4.5,"cheese",1995);
    Earthquakes Quake2 = new Earthquakes(6.5,"fish",1945);
    Earthquakes Quake3 = new Earthquakes(10.5,"Chorizo",2015);

    public void buildList(Earthquakes... args){
        for(Earthquakes myEarthquake : args){
            listOfEarthquakes.add(myEarthquake);
        }

    }
}


我的目的是建立一个地震对象清单。有人可以告诉我为什么以及如何修复我的代码吗?谢谢

- - - - - - - 编辑 - - - - - - - - - -

错误消息为the type ArrayList is not visible,但是将可见性修改器更改为public无效。

最佳答案

缺少以下导入语句

 import java.util.ArrayList;

 public class ObservatoryTest {

 private ArrayList <Earthquakes> listOfEarthquakes; //This list is not visible
    Earthquakes Quake1 = new Earthquakes(4.5,"cheese",1995);
    Earthquakes Quake2 = new Earthquakes(6.5,"fish",1945);
    Earthquakes Quake3 = new Earthquakes(10.5,"Chorizo",2015);

    public void buildList(Earthquakes... args){
        for(Earthquakes myEarthquake : args){
            listOfEarthquakes.add(myEarthquake);
        }

    }

09-30 21:43