Error 'null' in sockets connection , Android [duplicate]

狂风中的少年 提交于 2019-12-02 01:09:27

You need to print the stacktrace rather than just the exception message. That will give you more information to debug the problem ... including the name of the exception, and the place where it was thrown.

Also, it is a bad idea to catch Exception and attempt to recover from it. Catching Exception could catch all sorts of exceptions that you were never expecting. Recovering from exceptions that you weren't expecting is risky ... because you cannot be sure it is a safe thing to do. It is typically better to let the application die ...

I would like to give you some suggestions:

  1. use asynctask in android for networking activities otherwise NetworkOnMainThreadException occur because it is good to run all time consuming activities in background.Also keep in mind do all task in doBackgroung function of asynctask and then update and publish result with help of onPostExecute() and onProgress().
  2. If you are not using asynctask then simply use thread and perform all networking activity on separate thread.
  3. In java software ,track IP address by using Enumeration instead of InetAddress because Enumeration will show all IP address on network and probably you will find answer of your question.(Try to connect to all the IP that is shown by Enumeration method and connection is established with suitable one automatically)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!