应用程序在端口创建时死亡
尝试在以下代码中打开连接时,我的应用程序崩溃了。我相信这是因为该端口正在被使用,但我不确定。如果您发现下面的代码有任何问题或知道问题可能是什么,请告诉我。该应用程序使其能够
Log.v("connectdevice", "之后 ipadress");
有时它会超过这一点。但很少见。而且,没有发现异常。
提前致谢!
try {
Log.v("connectdevice", "inside make connection");
InetAddress host = InetAddress.getByName("192.168.201.65");
Log.v("connectdevice", "after ipadress");
socket = new Socket(host.getHostName(), 7777);
Log.v("connectdevice", "after socket");
connected = true;
} catch (UnknownHostException e) {
connected = false;
e.printStackTrace();
} catch (IOException e) {
connected = false;
e.printStackTrace();
}
My application crashes when trying to open a connection in the following code. I believe it is because the port is being used, but im not sure. Let me know if you see anything wrong with the code below or have any idea what the problem may be. The application makes it to
Log.v("connectdevice", "after
ipadress");
SOME times it will make it past that point. But is rarely. Also, there is no exception caught.
Thanks in advance!
try {
Log.v("connectdevice", "inside make connection");
InetAddress host = InetAddress.getByName("192.168.201.65");
Log.v("connectdevice", "after ipadress");
socket = new Socket(host.getHostName(), 7777);
Log.v("connectdevice", "after socket");
connected = true;
} catch (UnknownHostException e) {
connected = false;
e.printStackTrace();
} catch (IOException e) {
connected = false;
e.printStackTrace();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
这种方式你可以看到Logcat上的异常
Use
This way you can see the Exceptions on Logcat
如果 ssfn 过来并把他的答案放在这里,我会尽快接受。在那之前,这是公认的答案。
If ssfn comes by and puts his answer here, i am going to accept it asap. Until then, this is the accepted answer.