Inetaddress.getlocalhost () java.net.UnknownHostException exception handling __.net

Source: Internet
Author: User
Tags exception handling

In our development, if you want to obtain the IP address of the local machine, you can get it through Inetaddress.getlocalhost (), but a run-time exception that might be encountered is the corresponding configuration in the local configuration file. It's going to produce unknownhostexception. unknownhostexception cause the native name is not an IP address the native name is an IP address, but not the corresponding IP address of this computer The native name is an incomplete IP address with a different case solution

First we check the name of the machine by command line: [hostname]
Judging by the name of the machine is the reason for the above the solution to the host name is not an IP address

Host name If it is not the local IP address, you need to configure the host name and native IP through the format "IP native name" in the/etc/hosts file, so that the corresponding native name will get to the corresponding IP native name is an IP, but not the native IP

modifying the native IP host name to the correct native name is an incomplete IP

this situation in the acquisition process will not be reported unknownhostexception, but will access stagnation, the final report connection timed out of the exception, such cases need to modify the native name to the correct native IP corresponding string

- if the Inetaddress.getlocalhost () method is used in development, it is best to run a test in advance to see if you can get the correct IP for the deployed host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.