出现 java.net.MalformedURLException: no protocol 异常的原因及解决方法

1 异常描述

在通过 IP 地址及端口号调用远程方法,进行单元测试的时候,报出如下异常:

1

2 异常原因

通过观察上图标记出来的异常描述,咱们可以知道:

java.net.MalformedURLException: no protocol

此异常,为:no protocol,没有指定通信协议异常。

3 解决方法

既然咱们已经知道了是因为没有指定通信协议,从而导致异常的发生。

那么,咱们再回过头来,看看上面的 URL 是不是少了什么东西啊?少了吗?

好吧,答案是:没有指定 http 协议,在 URL 前面加上http://即可解决此异常

转载自:https://blog.csdn.net/qq_35246620/article/details/70162106

阅读更多

奇怪的异常java.net.MalformedURLException: unknown protocol: c

04-09

我在用数据库连接池,连数据库时读xml文件里出错,不知道怎么回事,我是重新配置的一个现成的案例,想看看人家怎么运行的,但是配置不出来,总是提示如下错误:rn2009-4-9 10:32:44 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/6.0.10rn正在读取配置文件......,请稍等rnjava.net.MalformedURLException: unknown protocol: crn at java.net.URL.(URL.java:574)rn at java.net.URL.(URL.java:464)rn at java.net.URL.(URL.java:413)rn at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)rn at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)rn at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)rn at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)rn at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)rn at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)rn at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)rn at org.jdom.input.SAXBuilder.build(SAXBuilder.java:489)rn at org.jdom.input.SAXBuilder.build(SAXBuilder.java:928)rn at com.ideas.util.ConfigReader.parseConfigXML(ConfigReader.java:33)rn at com.ideas.util.ConfigReader.(ConfigReader.java:20)rn at com.ideas.servlet.InitServlet.init(InitServlet.java:23)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)rn at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)rn at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4044)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:448)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:552)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rn正在读取配置文件......rnjava.net.MalformedURLException: unknown protocol: crn at java.net.URL.(URL.java:574)rn at java.net.URL.(URL.java:464)rn at java.net.URL.(URL.java:413)rn at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)rn at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)rn at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)rn at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)rn at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)rn at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)rn at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)rn at org.jdom.input.SAXBuilder.build(SAXBuilder.java:489)rn at org.jdom.input.SAXBuilder.build(SAXBuilder.java:928)rn at com.ideas.util.ConfigReader.parseConfigXML(ConfigReader.java:33)rn at com.ideas.util.ConfigReader.(ConfigReader.java:20)rn at com.ideas.servlet.InitServlet.init(InitServlet.java:23)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)rn at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)rn at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4044)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:448)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:552)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rn2009-4-9 10:32:46 org.apache.coyote.http11.Http11AprProtocol startrn信息: Starting Coyote HTTP/1.1 on http-8080rn2009-4-9 10:32:46 org.apache.coyote.ajp.AjpAprProtocol startrn信息: Starting Coyote AJP/1.3 on ajp-8009rn2009-4-9 10:32:46 org.apache.catalina.startup.Catalina startrn信息: Server startup in 1578 ms

没有更多推荐了,返回首页