Java.net.UnknownHostException Exception Handling

Source: Internet
Author: User

About java.net.UnknownHostException Everyone may be more familiar with, today I will tidy up about the java.net.UnknownHostException of the various methods of treatment:

1. Add access to the network in Androidmanifest.xml in Android Project : <uses-permission android:name= "Android.permission.INTERNET"/ >;

2, visit the site has been closed/closed or not exist, can be verified in the browser;

3, unable to resolve the domain name, the domain name corresponding to the IP write to the hosts file to save.

The Hosts file for Windows is in "c:\windows\system32\drivers\etc".

Linux changes the hosts operation as follows:

cd/etc/

vi hosts

input:
211.151.71.11 www.xxxx.com

4, there is also a problem is the mobile network settings, If you encounter this problem, you can change your phone network settings to 3gnet or other network.

Below is a detection network type of program for everyone to detect the type of mobile network (also can be viewed directly in the phone settings):

Public string nettype (Context context)  {         try {            connectivitymanager cm  =  (Connectivitymanager)  context.getsystemservice (context.connectivity_service);             NetworkInfo info =  Cm.getactivenetworkinfo ();            string  Typename = info.gettypename (). toLowerCase (); // wifi/mobile             if  (Typename.equalsignorecase ("WiFi")  {             } else {                 typename = info.getextrainfo (). toLowerCase ();                // 3gnet/3gwap/uninet/uniwap/cmnet/ cmwap/ctnet/ctwap            }             return typeName;         } catch  (exception e)  {             return null;        }     }

Java.net.UnknownHostException Exception Handling

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.