我正在处理大量导入的数据,并使用2类(WeatherStation,WeatherReading)在主要方法中检索其中的某些部分。数据是气象站负载(站号,名称,纬度,经度,年,时间,温度等)我制作了第三类(SoloSiteIds),其唯一目的是返回站点ID的完整且完整的ArrayList,而不重复。但是我不能将ArrayList从另一个类导入到我的main方法中。我的SoloSiteIds类如下所示:
public class SoloSiteIds {
static ArrayList <Integer> siteIds = new ArrayList <Integer>();
public SoloSiteIds() {
}
public SoloSiteIds( ArrayList <Integer> siteIds) {
String[] weatherData = WeatherData.getData();{ // get the weather data
for (int i = 1; i < weatherData.length; i++) {
String line = weatherData[i];
String[] elements = line.split(","); // Split the data at ",
String siteid = elements[0]; // convert all the site id's at index 0 to integers
int id = Integer.parseInt(siteid);
if(!siteIds.contains(id)) {
siteIds.add(id);
}
this.siteIds=siteIds;
}
}
}
public static ArrayList<Integer> getSiteIds() {
return siteIds;
}
public ArrayList<Integer> setSiteIds(ArrayList<Integer> siteIds) {
return this.siteIds = siteIds;
}
}
我尝试导入ArrayList“ siteIds”的主要方法如下:
WeatherStation thisStation = new WeatherStation (id, name, lat, lon);
WeatherReading thisReading = new WeatherReading(year, month, date, hour, windSpeed, temp);
SoloSiteIds siteList= new SoloSiteIds();
String[] weatherData = WeatherData.getData();{ // get the weather data
for (int i = 1; i < weatherData.length; i++) {
String line = weatherData[i];
String[] elements = line.split(","); // Split the data at ","
String siteid = elements[0]; // convert all the site id's at index 0 to integers
id = Integer.parseInt(siteid);
thisStation.setId(id);
thisStation.setName(elements[1]);
//parse the different elements into different data types
String stringLat = elements[2];
lat= Double.parseDouble(stringLat);
lat = thisStation.setLat(lat);
lat=thisStation.setLat(lat);
String stringLon = elements[3];
lon= Double.parseDouble(stringLon);
lat = thisStation.setLon(lon);
lat=thisStation.setLon(lon);
String stringTemp=elements[9];
temp=Double.parseDouble(stringTemp);
temp=thisReading.setTemp(temp);
仅顶部是相关的。我尝试使用“ thisList”实例和新的ArrayList来尝试.set和.get的许多不同变体
ArrayList<Integer> siteIds = thisList.setSiteIds();
ArrayList<Integer> siteIds= SoloSiteIds.getSiteIds();
thisList=Siteids.setSiteIds();
thisList=SingleSoloSites.setSiteIds();
等等等。这可能看起来很愚蠢,但我只是表明我已经尝试了很多事情,我被困了,谢谢
我相信您的问题是,您正在将siteIds初始化为一个空的Arry列表,但是您不是以静态方式设置数据(set Method不是静态的)。
据您所知,我相信SoloSiteIds类是不必要的。我将通过在主类中声明的ArrayList解决问题,并使用也在主类中声明的getSoleIds()方法进行初始化。getSoleIds()方法应包含SoleSiteIds初始化程序中当前的代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句