Copying from list to list

I have a list

List result = pm.select(SupremeApplicationElement.class, attName, args);

I want to copy just the elements with "POP" in the description

List pop_result =null;

for(int k=0; k<result.size(); k++){

String s =(String) ((SupremeApplicationElement) result.get(k)).getAttribute("description");

if(s.equals("POP")){

pop_result .add(result.get(k));

model_pop.setAttribute("popRes",pop_result);

}

}

But I'm getting Null pointer exception... Help pls..>

[845 byte] By [New_Kida] at [2007-11-27 10:12:10]
# 1

> List pop_result = null;

> pop_result .add(result.get(k));

Where are you initializing the pop_result list before adding elements to it?

aniseeda at 2007-7-28 15:18:36 > top of Java-index,Java Essentials,Java Programming...
# 2

> > List pop_result = null;

>

> > pop_result .add(result.get(k));

>

> Where are you initializing the pop_result list

> before adding elements to it?

Its exactly as you see.. I tried adding Arrays.asList(new String [] {"a","b"}

instead of the object from "result" and it worked.

New_Kida at 2007-7-28 15:18:36 > top of Java-index,Java Essentials,Java Programming...
# 3

The problem is in the first line itself.

List pop_result = null;

Change it to ....

List pop_result = new ArrayList();

vinayak_ra at 2007-7-28 15:18:37 > top of Java-index,Java Essentials,Java Programming...