[英]NullPointerException when attempting ConcurrentHashMap.get()
I have the following code:我有以下代码:
public class MyEvent implements org.apache.camel.Processor
{
static private final Map<Long, String> obj = new ConcurrentHashMap<Long, String>();
@PostConstruct
public void postConstruct()
{
for (Object object : cacheList)
{
obj.put(object.getId(), object.getName());
}
}
@Override
public void process(Exchange exchange) throws Exception
{
synchronized (obj)
{
String value = obj.get(number);
}
}
}
Sometimes when starting, I have a NullPointerException
in this line:有时在启动时,我在这一行中有一个
NullPointerException
:
String value = obj.get(number);
My question is: Why do I get this error and how can I fix it?我的问题是:为什么我会收到这个错误,我该如何解决?
Java version 1.6.0_32 Java 版本 1.6.0_32
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.