Java 无法连接到 Eclipse 中的虚拟机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19633502/
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-08-12 18:59:08  来源:igfitidea点击:

Cannot connect to VM in Eclipse

javaeclipsedebuggingjdwp

提问by Menezes Sousa

I have suddenly begun getting this weird error when I try to debug any of my projects on Eclipse. I don't remember changing anything for this problem to start so suddenly.

当我尝试在 Eclipse 上调试我的任何项目时,我突然开始收到这个奇怪的错误。我不记得为了这个问题突然开始改变任何东西。

'Launching <my program name>' has encountered a problem.
Cannot connect to VM.

Details of the error:

错误详情:

Cannot connect to VM
com.sun.jdi.connect.TransportTimeoutException

Further, in the console I get the following error:

此外,在控制台中,我收到以下错误:

FATAL ERROR in native method: JDWP No transports initialized, 
jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: connect failed: Connection timed out
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized     
[../../../src/share/back/debugInit.c:750]

Please tell me how to solve this problem. I have searched the whole web for an answer but to no luck.

请告诉我如何解决这个问题。我在整个网络上搜索了答案,但没有运气。

I tried the following solutions which worked for other people:

我尝试了以下对其他人有用的解决方案:

  1. Restarted Eclipse, restarted computer.
  2. Change hosts file in etc\ - Remove the comments (#) sign before 2 lines namely,

    127.0.0.1 localhost

    ::1 localhost

    and restarted.

  3. Turned off all firewalls, restarted Eclipse and retried. Still no luck.
  1. 重新启动 Eclipse,重新启动计算机。
  2. 更改 etc\ 中的 hosts 文件 - 即删除 2 行前的注释 (#) 符号,

    127.0.0.1 本地主机

    ::1 本地主机

    并重新启动。

  3. 关闭所有防火墙,重新启动 Eclipse 并重试。仍然没有运气。

Somebody please help me, I'm going crazy.

有人请帮助我,我快疯了。

Thanks

谢谢

Sousa

苏萨

采纳答案by Sebastien Diot

I just found this: Avast! 2014I have it, and so it fits. If you do as well, then that is probably your problem.

我刚刚发现这个:Avast!2014我有它,所以它适合。如果你也这样做,那么这可能是你的问题。

回答by antony.ouseph.k

I think the problem is because you have set the wrong path to jre .try right click on your project and click run configuration and set jre correct path. Could you please elaborate more about the issue.

我认为问题是因为您为 jre 设置了错误的路径。尝试右键单击您的项目并单击运行配置并设置 jre 正确的路径。您能否详细说明一下这个问题。

回答by Menezes Sousa

After much stress and a lot of time, the problem is now resolved. Albeit in a very freaky way which does not amuse me as I can't figure out the rationale behind it. Anyways, here is what happened and maybe someone can throw some more light on what could have been the root cause of the problem.

经过大量压力和大量时间后,问题现在得到了解决。尽管以一种非常怪异的方式不会让我感到有趣,因为我无法弄清楚其背后的基本原理。无论如何,这就是发生的事情,也许有人可以更多地了解可能是问题的根本原因。

I uninstalled Eclipse and Java completely from my system.

我从我的系统中完全卸载了 Eclipse 和 Java。

I then re-installed the latest version of Java (I had this same version previously too).

然后我重新安装了最新版本的 Java(我以前也有这个相同的版本)。

But this time I installed it in the standard directory and not the custom directory that I was using before (Probably something here was wrong the first time).

但是这次我安装在标准目录而不是我之前使用的自定义目录(可能是第一次这里出了问题)。

I then re-installed Eclipse (latest version again).

然后我重新安装了 Eclipse(再次安装了最新版本)。

And just like that, it all started working normally again, Debug mode and everything!

就这样,一切又开始正常工作了,调试模式等等!

What immediately comes to my mind is that the system environment variables could have got changed somehow. But I don't understand how this could have happened without me touching anything.

我立即想到的是系统环境变量可能以某种方式改变了。但我不明白如果没有我接触任何东西,这怎么会发生。

回答by Riccardo Amaduzzi

disable windows firewall and it's OK. TESTED.

禁用windows防火墙就OK了。测试。

回答by Lokesh

Sometimes when you try to debug your application, you will get the error like

有时当你尝试调试你的应用程序时,你会得到这样的错误

Cannot connect to VM 
com.sun.jdi.connect.TransportTimeoutException
FATAL:----------
ERROR:------------
ERROR:----------
WARN:-------------

I suggest you to turn-off your AVAST! FIREWALL and restart your system and then try debug your application. It will work fine.

我建议你关掉你的AVAST!防火墙并重新启动您的系统,然后尝试调试您的应用程序。它会正常工作。

Thanks Lokesh

谢谢洛克什

回答by weis

I ran into the same problem. It turned out that I have changed my /etc/hosts file where the ip address 127.0.1.1 was commented out. After uncommented it, it started to work again.

我遇到了同样的问题。原来我已经更改了我的 /etc/hosts 文件,其中 ip 地址 127.0.1.1 被注释掉了。取消注释后,它又开始工作了。

回答by RIP_SunMicroSys

Simply restart your PC,it sounds silly but works most of the times., I don't have avast in my PC, but still ran into this problem.

Simply restart your PC,这听起来很傻,但在大多数情况下都有效。我的电脑中没有avast,但仍然遇到了这个问题。

Just restarted my PC and debug worked, I'm not sure what might be the problem exactly though.

刚刚重新启动了我的 PC 并进行了调试,但我不确定到底是什么问题。

回答by Lucky

For me I had this issue when starting up the jetty-server and McAfee Antivirus Protectionsoftware was installed in my Windows 7 64 bit PC and as other mentioned I diabled the Firewalloption and restarted eclipse workspace and started the server again. It worked!!!

对我来说,我在启动 jetty-server 时遇到了这个问题,并且McAfee Antivirus Protection软件安装在我的 Windows 7 64 位 PC 中,正如其他人提到的,我禁用了防火墙选项并重新启动了 eclipse 工作区并再次启动了服务器。有效!!!

Listening for transport dt_socket at address: 9000

Listening for transport dt_socket at address: 9000

I doubt there is a way to enable the port without disabling the firewall or maybe whitelist the specific port to be allowed by my antivirus softwares since this wont change often. Will post an update if I find one.

我怀疑是否有一种方法可以在不禁用防火墙的情况下启用端口,或者可能将我的防病毒软件允许的特定端口列入白名单,因为这不会经常改变。如果我找到一个会发布更新。

回答by Павел Бивойно

I had a similar problem, when working with scrapbook. Fireval was in game mode. Then I turned off Fireval and scrapbook began to work.

在使用剪贴簿时,我遇到了类似的问题。Fireval 处于游戏模式。然后我关闭了 Fireval,剪贴簿开始工作。

回答by vraa

Same symptoms appeared quite suddenly after my setup had worked nocely for long time. The reason appeared one invalid line in my /etc/hosts file (I had added virtual NIC's ip there with translation to 'localhost'). Removing that line fixed it.

在我的设置正常工作很长时间后,同样的症状突然出现。原因在我的 /etc/hosts 文件中出现了一行无效的行(我在那里添加了虚拟 NIC 的 ip 并转换为“localhost”)。删除该行修复了它。

For someone with C background it is bit surprising that Eclipse reads /etc/hosts when you are debugging local Java application, but that appears to be the case.

对于具有 C 背景的人来说,在调试本地 Java 应用程序时 Eclipse 读取 /etc/hosts 有点令人惊讶,但事实似乎确实如此。