package mp1similar;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import EarthquakeRecord.Earthquakerecd;
public class MP1Similar
{
private static ArrayList arrayList ;
public static void main(String[] args)
{
ArrayList arrayList= null;
try
{
BufferedReader br = new BufferedReader(new FileReader("data/Catalog.txt"));
String line="";
arrayList =new ArrayList();
while((line = br.readLine())!=null)
{
// System.out.println(line);
StringTokenizer st = new StringTokenizer(line);
while(st.hasMoreTokens())
{
//System.out.println(st.nextToken());
arrayList.add(st.nextToken());
//System.out.println(br.readLine());
}
}
}
catch (FileNotFoundException ex)
{
System.out.println(ex.getMessage());
ex.printStackTrace();
}
catch (IOException ex)
{
System.out.println(ex.getMessage());
ex.printStackTrace();
}
int j=0;
Earthquakerecd E[]= new Earthquakerecd[2000];
for(int i=0;i< arrayList.size();i++)
{
System.out.println(arrayList.get(i));
E[j] = new Earthquakerecd();
E[j].setDate(arrayList.get(i));
if (j>35)
{
j=0;
}
j++;
}
}
}
我得到一行錯誤E[j].setDate(arrayList.get(i));
它說實際參數不能通過方法調用轉換爲java.lang.String
。使用ArrayList類型錯誤?
該對象中的所有字段均爲String
類型。 arrayList包含從TXT文件中提取的所有數據。我正在嘗試將所有數據從arrayList傳遞到對象數組。 txt文件有35列和1500行。該數據被分隔用空格
我有一個問題,在ArrayList中我有差異的數據類型,而不只是字符串,我已經整型,浮點,雙,那我該怎麼辦? – 2012-02-06 21:21:05