程序莫名其妙出了 error:java.lang.NullPointerException: Null reference used for synchronization (monitor-enter) 就是在使用同步锁的时候,是锁的对象是空的。很是奇怪,看代码没觉得啊。打印一下,确实是空的,Why?
public String getApplicationContext(){ return"string"; } }
没问题啊?
猜一下结果输出?出错拉!!
1 2 3 4 5 6 7
Exception in thread "main" java.lang.ExceptionInInitializerError at SynTest.main(SynTest.java:3) Caused by: java.lang.NullPointerException at LockInstance.getInstance(SynTest.java:11) at LockInstance.getString(SynTest.java:16) at LockInstance.<clinit>(SynTest.java:8) ... 1 more