Java: ListA.addAll(ListB) fires NullPointerException?
Posted
by HH
on Stack Overflow
See other posts from Stack Overflow
or by HH
Published on 2010-05-08T05:10:43Z
Indexed on
2010/05/08
5:18 UTC
Read the original article
Hit count: 168
The err part is Capitalized in the code, it also comes in foreaching. Because of the abstract list, it cannot be initialized, declaration is in a static field. The lists have the same type.
import java.util.*;
public class Test
{
public static final List<String> highPrio = Arrays.asList("*","/");
public static List<String> ops;
public static void main(String[] args)
{
//ERROR HERE, why do it throw nullPointer?
ops.addAll(highPrio);
for(String s : ops)
{
System.out.println(s);
}
}
}
© Stack Overflow or respective owner