送分啊....简单java 问题
package com.test;
import java.util.*;
public class test {
public static void main (String[] args){
ArrayList arraylist=new ArrayList();
for (int i = 0; i <10 ;i++) {
Article article=new Article(i+ " ", "article "+i);
Article article1=new Article(i+ " ", "article "+i);
arraylist.add(article);
arraylist.add(article1);
}
Iterator iterator=arraylist.iterator();
ArrayList a1=null;
int i=0;
while(iterator.hasNext()){
Article article=(Article)iterator.next();
String s1=article.getId();
System.out.println(s1);
a1.add(s1); //这里为什么会错
}
}
}
------解决方案--------------------a1没有初始化
------解决方案--------------------a1是个空对象啊,会报NullPointException
------解决方案--------------------null.add(s1)?
ArrayList a1 = new ArrayList();