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