我将项目导入eclipse并添加了依赖项(只有oracle驱动程序和junit4)。但是当我尝试运行项目时,我得到一个ExceptionInInitializerError。我出于某种原因无法初始化某些变量。
我知道该项目没问题,所以我认为这是JDK的一个问题。
我曾尝试过瞪眼,但我没有得到任何解决方案。
非常感谢任何帮助。
java.lang.ExceptionInInitializerError
at com.ats.dao.RetrievalDAO.<init>(RetrievalDAO.java:27)
at com.ats.dao.test.RetrievalDAOTest.testinsertmessage(RetrievalDAOTest.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.ats.util.Config.<init>(Config.java:17)
at com.ats.retriever.DBPropertiesRetriever.<clinit>(DBPropertiesRetriever.java:11)
... 25 more
答案 0 :(得分:2)
您的堆栈跟踪告诉您需要知道的内容。这些行:
java.lang.ExceptionInInitializerError
at com.ats.dao.RetrievalDAO.<init>(RetrievalDAO.java:27)
at com.ats.dao.test.RetrievalDAOTest.testinsertmessage(RetrievalDAOTest.java:49)
...
...告诉您,您的代码在RetrievalDAO类的构造函数中遇到错误,同时由RetrievalDAOTest(可能是单元测试)运行。该例外还由以下原因引起:
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.ats.util.Config.<init>(Config.java:17)
at com.ats.retriever.DBPropertiesRetriever.<clinit>(DBPropertiesRetriever.java:11)
...它告诉您实际错误是由Config类的初始化引起的。检查Config类在第17行的作用,以及为什么它可能将null传递给Properties加载器。