0

我正在向我的数组列表添加一个值,但它显示错误。在添加值之前,我先显示它。该值正在显示,但未添加到数组列表中。请帮我解决这个问题...

我的代码:

static ArrayList<String> allfirstids;

ArrayList<String> list = List.get(i);
UserBO user = new UserBO();

user.firstid = Integer.parseInt(list.get(0));
user.secondid = Integer.parseInt(list.get(1));
System.out.print("Hello this is first id");
System.out.print(list.get(0));

allfirstids.add(list.get(0));
System.out.println("first ids"+allfirstids);

提前致谢...

4

2 回答 2

5

添加前,请先初始化arraylist。

 allfirstids = new ArrayList<String>();
于 2012-04-23T05:00:45.077 回答
1

你忘了初始化你的静态ArrayList allfirstids,只需初始化它,然后再使用..

static ArrayList<String> allfirstids = new ArrayList<String>();

ArrayList<String> list = List.get(i);
UserBO user = new UserBO();

user.firstid = Integer.parseInt(list.get(0));
user.secondid = Integer.parseInt(list.get(1));
System.out.print("Hello this is first id");
System.out.print(list.get(0));

allfirstids.add(list.get(0));
System.out.println("first ids"+allfirstids);
于 2012-04-23T05:01:22.700 回答