我正在尝试构建一个ArrayList of Earthquake对象,但是Earthquake抱怨说它不可见。
我的守则:
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没有任何效果。
发布于 2015-10-29 17:16:21
缺少以下导入语句
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);
}
}发布于 2015-10-29 17:20:45
出于某种原因,您已经将输入按需申报用于Arrays的嵌套成员
import java.util.Arrays.*;在当前的实现中,Arrays声明了一个名为ArrayList的private嵌套类型。这在代码中是不可见的,因为它是private。
您的意思是导入java.util.ArrayList。
发布于 2015-10-29 17:13:59
您缺少了ArrayList的导入语句
import java.util.ArrayList;要解决这些问题,请调用SDE的“组织导入”。在Eclipse中:Ctrl O
https://stackoverflow.com/questions/33420532
复制相似问题