方法后ArrayList为空

时间:2014-10-09 13:29:04

标签: java android arraylist

我有一些我不明白的东西。我有一个私有arrayList并在函数中使用它,它也获取并存储值,但只有在方法完成之后。任何提示我的错误在哪里?

private ArrayList<MyEventClass> myeventList = new ArrayList<MyEventClass>();

private void get(){
    System.out.println("Size: " + myeventList.isEmpty());
    System.out.println("Size: " + myeventList.toString());

    if(myeventList.isEmpty()) {
        myeventArrayList = downloadEvent();

        for (int position = 0; position < myeventArrayList.size(); position++) {
            MyEventClass currentEvent = new MyEventClass(myeventArrayList.get(position).get("name").toString(), myeventArrayList.get(position).get("location"), myeventArrayList.get(position).get("date")
                    , myeventArrayList.get(position).get("type"), myeventArrayList.get(position).get("theme"), myeventArrayList.get(position).get("link"), Integer.parseInt(myeventArrayList.get(position).get("myevents_ref")));
            myeventList.add(currentEvent);
        }

    }

    System.out.println("Size: " + myeventList.isEmpty());
    System.out.println("Size: " + myeventList.toString());
}

每次我得到相同的结果:

Size: true
Size: []
Size: false
Size: [com.hobbyathletes.hobbyathletes.Object.MyEventClass@4218bb60, com.hobbyathletes.hobbyathletes.Object.MyEventClass@4218bfb0, com.hobbyathletes.hobbyathletes.Object.MyEventClass@4218c3b8]

为什么不是第二次isEmpty == true的结果?

THX MD

0 个答案:

没有答案