eclipse 启动tomcat时出现空指针异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27357092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:16:51  来源:igfitidea点击:

nullpointer exception in starting tomcat

javaeclipsetomcat

提问by Techno

my tomcat server is not starting in eclipse which was working fine before but now its showing the following exception. although its working quite fine outside eclipse. but whenever i try to start the server, the following exception occurs and it shows the message = " starting Tomcat server v8.0 server at localhost has encountered a problem"

我的 tomcat 服务器没有在 eclipse 中启动,之前运行良好,但现在显示以下异常。虽然它在日食之外工作得很好。但是每当我尝试启动服务器时,都会发生以下异常,并显示消息 =“在本地主机上启动 Tomcat 服务器 v8.0 服务器遇到问题”

Dec 08, 2014 4:35:16 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-nio-8009"]
Dec 08, 2014 4:35:16 PM org.apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
java.lang.NullPointerException
    at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:307)
    at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:482)
    at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:795)
    at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:531)
    at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
    at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
    at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:850)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

回答by Stephen C

The stacktrace seems to show that Tomcat has already decided that the startup has failed, and that the NPE occurred while trying to shutdown.

stacktrace似乎显示Tomcat已经判断启动失败,尝试关机时出现NPE。

I expect that the real problem (i.e. the one that caused Tomcat to abandon the startup attempt) is earlier in the log file.

我希望真正的问题(即导致 Tomcat 放弃启动尝试的问题)在日志文件中较早出现。



Indeed the Tomcat source code confirms this:

事实上,Tomcat 源代码证实了这一点:

protected void releaseCaches() {
    this.keyCache.clear();
    this.nioChannels.clear();
    this.processorCache.clear();
    if ( handler != null ) handler.recycle();
}

A NullPointerException here means that keyCacheor nioChannelsor processorCacheis null. (I think) that can only happen if something went wrong during the construction of the NioEndPointobject because those three fields are private final. Or at least, they are in the version I looked at.

此处的 NullPointerException 表示keyCacheornioChannelsprocessorCacheis null。(我认为)只有在NioEndPoint对象的构造过程中出现问题时才会发生这种情况,因为这三个字段是private final. 或者至少,它们在我看过的版本中。

回答by SpareTheRod

This happened to me, it was because I had misconfigured my Tomcat server. Deleting it and creating a new server entry helped.

这发生在我身上,这是因为我错误地配置了我的 Tomcat 服务器。删除它并创建一个新的服务器条目有帮助。