I\'ve created an app that loads a question from my web services, and it works fine. But, sometimes it crashes and I do not get the reason why this is happening, especially b
If reconnecting the WiFi doesn't work for you, try reboot your device.
This works for me. Hope it helps.
Missed to configure tag in manifest file
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I encountered this error when running my Android app on my home WiFi, then trying to run it on different WiFi without closing my simulator.
Simply closing the simulator and re-launching the app worked for me!
I had the same problem, but with small difference. I had added NetworkConnectionCallback to check situation when internet connection had changed at runtime, and checking like this before sending all requests:
private fun isConnected(): Boolean {
val activeNetwork = cManager.activeNetworkInfo
return activeNetwork != null && activeNetwork.isConnected
}
There can be state like CONNECTING (you can see iе when you turn on wifi, icon starts blinking, after connecting to network, image is static). So, we have two different states: one CONNECT another CONNECTING, and when Retrofit tried to send request internet connection is disabled and it throws UnknownHostException. I forgot to add another type of exception in function which was responsible for sending requests.
try{
//for example, retrofit call
}
catch (e: Exception) {
is UnknownHostException -> "Unknown host!"
is ConnectException -> "No internet!"
else -> "Unknown exception!"
}
It's just a tricky moment that can by related with this problem.
Hope, I will help somebody)
I got the same error and the issue was that I was on VPN and I didn't realize it. After disconnecting from the VPN and reconnecting to my WIFI network, the problem was resolved.