无法打开调试器端口:java.net.ConnectException“连接被拒绝”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28283087/
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
Unable to open debugger port : java.net.ConnectException "Connection refused"
提问by Kleiber J. Perez
I'm using Android Studio v1.0.1 to build an app in macOS Yosemite 10.10. When I try to debug the app, it installs correctly but has the error
我正在使用 Android Studio v1.0.1 在 macOS Yosemite 10.10 中构建应用程序。当我尝试调试应用程序时,它安装正确但出现错误
Error running [app]: Unable to open debugger port : java.net.ConnectException "Connection refused"
运行 [app] 时出错:无法打开调试器端口:java.net.ConnectException“连接被拒绝”
When I run the DDMS, it shows the connected devices and the process. The trouble occurs just when trying to debug in Android Studio.
当我运行 DDMS 时,它会显示连接的设备和过程。只是在 Android Studio 中尝试调试时出现问题。
In other forums, I've found that something could have changed the port of the debugger, but that doesn't solve my issue.
在其他论坛中,我发现有些东西可能会改变调试器的端口,但这并不能解决我的问题。
采纳答案by bonnyz
Your debug port is probably busy (in use by another process). You can kill all the process associated with the ADB debug port (8601 or higher) using this:
您的调试端口可能正忙(正在被另一个进程使用)。您可以使用以下命令终止与 ADB 调试端口(8601 或更高版本)相关的所有进程:
fuser -k 8601/tcp
UPDATE:
更新:
Under OSX, lsof
should do the job in substitution of fuser
:
在OSX 下,lsof
应该做的工作是代替fuser
:
lsof -i :8601
回答by Andre
You can use netstat
utility to see what is listening on what ports and, if you are quick, what tries to connect to what ports. This will help to to ensure that you have your process listening on a debugging port and confirm its number.
您可以使用netstat
实用程序来查看正在侦听哪些端口的内容,如果速度快,还可以查看哪些内容尝试连接到哪些端口。这将有助于确保您的进程侦听调试端口并确认其编号。
回答by VicX
I have also met this problem. and I think the my solution may help others, so I post it here.
我也遇到过这个问题。我认为我的解决方案可以帮助其他人,所以我把它贴在这里。
First, you should know what will cause "connection refused" problem. Usually there are two possible reasons:
首先,您应该知道什么会导致“连接被拒绝”问题。通常有两种可能的原因:
- This particular server is not started.
- The server is started but not accept any connection.
- 此特定服务器未启动。
- 服务器已启动但不接受任何连接。
As for your problem, I suggest you to first start your Android Device Monitor(DDMS) from your android studio, and DO NOT CLOSE IT.
至于你的问题,我建议你先从你的安卓工作室启动你的安卓设备监视器(DDMS),不要关闭它。
Then in the DDMS, you can select the package you want to debug and "Update Threads", and now you can debug this application in your studio.
然后在 DDMS 中,您可以选择要调试的包和“更新线程”,现在您可以在您的工作室中调试此应用程序。
回答by Dhaval Jivani
My problem Solved by below steps:
我的问题通过以下步骤解决:
1. Invalidate Caches/Restart Android studio
1. 使缓存失效/重启 Android Studio
2. Restart you Emulator.
2. 重启你的模拟器。
Done for me.
为我完成。
回答by Anjan Kant
Restartedmy Android Studio, worked for me.
重新启动我的Android Studio,为我工作。
回答by Shubham Raitka
I had this problem when I was using a real device, I just unplugged the USB cable and then again plugged it in and it worked. In case of emulators, I guess restarting the emulator will work. This works because disconnecting the device/emulator closes all connected processes, and then you start your required process.
我在使用真实设备时遇到了这个问题,我只是拔掉了 USB 电缆,然后再次插入,它就可以工作了。在模拟器的情况下,我想重新启动模拟器会起作用。这是有效的,因为断开设备/模拟器会关闭所有连接的进程,然后您开始所需的进程。
回答by Saravanan Kathiresan
For me none of the above solved and got stuck in this for months until I figured this solution. I had a modified version of my HOST file in my mac machine like pointing the IP 127.0.0.1 to a custom domain like www.mymac.com. Once I reverted that then I am able to debug. Yes!!! hope this helps for some one.
对我来说,以上都没有解决,并且在我想出这个解决方案之前被困在这个问题上好几个月。我在我的 mac 机器中有我的 HOST 文件的修改版本,比如将 IP 127.0.0.1 指向一个自定义域,比如 www.mymac.com。一旦我恢复了,那么我就可以调试了。是的!!!希望这对某些人有所帮助。
回答by Saravanan Kathiresan
I also solved this by making 127.0.0.1 in my Mac hosts file NOT point to a custom domain. One thing to note, I had 2 host files, one in "/" and one "/etc". One in "/etc" was actually used.
我还通过在我的 Mac 主机文件中设置 127.0.0.1 NOT 指向自定义域来解决这个问题。需要注意的一件事是,我有 2 个主机文件,一个在“/”中,一个在“/etc”中。实际使用了“/etc”中的一个。
回答by Bakavani
It was a /etc/hosts file issue for me as well, I changed the following line (dont know why it was working before ... after upgrade to studio 3.1.3 it stopped working though!)
这对我来说也是一个 /etc/hosts 文件问题,我更改了以下行(不知道它为什么在之前工作......升级到工作室 3.1.3 后它停止工作了!)
127.0.1.1 localhost
to
到
127.0.0.1 localhost
回答by Ramesh Hawking
For Windows user you can kill the port by using the following command ..
对于 Windows 用户,您可以使用以下命令终止端口..
Step 1:
第1步:
Open the cmd (note: you may need to run it as an administrator, but this isn't always necessary), then run the below command:
打开 cmd(注意:您可能需要以管理员身份运行它,但这并不总是必要的),然后运行以下命令:
netstat -ano | findstr :PORT_NUMBER
netstat -ano | findstr :PORT_NUMBER
Step 2:
第2步:
Syntax:
taskkill /PID PORT_NUMBER /F
cmd:
taskkill /PID 5005 /F