【发布时间】:2014-03-20 13:35:27
【问题描述】:
主类:
ArrayList<LinkedList> my_lists = new ArrayList<LinkedList>();
try {
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String line = sc.nextLine();
LinkedList the_list = new LinkedList();
String[] templist = line.split("\\s*,\\s*");
for(int i=0; i<templist.length; i++){
temp = templist[i];
the_list.add(temp);
System.out.println(templist[i]);
}
my_lists.add(the_list);
System.out.println(line);
}
sc.close();
}
从我的 LinkedList 类中添加方法:
public void add (Object newData){
Node cache = head;
Node current = null;
while ((current = cache.next) != null)
cache = cache.next;
cache.next = new Node(newData,null);
}
每次我为该行运行它时都会出现错误:the_list.add(temp); 有什么想法吗?
【问题讨论】:
-
返回的具体错误/堆栈跟踪是什么?
标签: java arrays list linked-list add