关于类似“Can't bind to local 8602 for debugger”错误的解决方案

时间:2022-04-02 20:54:20

为了适应Android5.0的开发,把JDK升级到了1.7,然后在ADT中想调试一下程序(我连接的真机),结果报错如下:

[2015-04-23 15:31:37 - ddms] Can't bind to local 8602 for debugger
[2015-04-23 15:31:37 - ddmlib] 您的主机中的软件中止了一个已建立的连接


java.io.IOException: 您的主机中的软件中止了一个已建立的连接。
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(Unknown Source)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.write(Unknown Source)
at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
at com.android.ddmlib.JdwpPacket.writeAndConsume

(JdwpPacket.java:213)
at com.android.ddmlib.Client.sendAndConsume(Client.java:642)
at com.android.ddmlib.HandleHeap.sendREAQ

(HandleHeap.java:348)
at com.android.ddmlib.Client.requestAllocationStatus

(Client.java:488)
at com.android.ddmlib.DeviceMonitor.createClient

(DeviceMonitor.java:835)
at com.android.ddmlib.DeviceMonitor.openClient

(DeviceMonitor.java:803)
at com.android.ddmlib.DeviceMonitor.processIncomingJdwpData

(DeviceMonitor.java:763)
at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop

(DeviceMonitor.java:652)
at com.android.ddmlib.DeviceMonitor.access$100

(DeviceMonitor.java:44)
at com.android.ddmlib.DeviceMonitor$3.run

(DeviceMonitor.java:580)


根据错误信息猜想应该是debug端口被占用了,本以为是升级1.7引起的,*上也有人说卸掉1.7,重新装1.6就好了。想想不应该啊,Android 5.0要求JDK必须升级到1.7的,忽然发现我同时还在跑Android Studio,同样也连接我的手机,抓到元凶,一定就是这货了!果断关掉Android Studio,然后在ADT中clean下工程,重新运行程序就OK了。如果碰到上述情况,也许不一定是Android Studio占用了debug 端口,或者还有其他进程占用,请不要怀疑是JDK1.7的问题。