gpt4 book ai didi

java - Android 应用程序在重新启动时崩溃 java.net.UnknownHostException : Unable to resolve host

转载 作者:行者123 更新时间:2023-12-01 11:52:27 27 4
gpt4 key购买 nike

当我重新启动我的设备时,它使我的应用程序崩溃,很难调试,我搜索的内容是说要添加我在 list 中拥有的互联网权限,我不知道该怎么做,有人可以吗?指导我。

02-24 17:37:05.750: I/System.out(5201): onErrorResponse:com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "eventiapp.com": No address associated with hostname
02-24 17:37:05.750: W/System.err(5201): com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "eventiapp.com": No address associated with hostname
02-24 17:37:05.750: W/System.err(5201): at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:133)
02-24 17:37:05.750: W/System.err(5201): at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
02-24 17:37:05.750: W/System.err(5201): Caused by: java.net.UnknownHostException: Unable to resolve host "eventiapp.com": No address associated with hostname
02-24 17:37:05.755: W/System.err(5201): at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
02-24 17:37:05.755: W/System.err(5201): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
02-24 17:37:05.755: W/System.err(5201): at java.net.InetAddress.getAllByName(InetAddress.java:214)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
02-24 17:37:05.755: W/System.err(5201): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
02-24 17:37:05.755: W/System.err(5201): at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:227)
02-24 17:37:05.755: W/System.err(5201): at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:210)
02-24 17:37:05.755: W/System.err(5201): at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:106)
02-24 17:37:05.755: W/System.err(5201): at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
02-24 17:37:05.755: W/System.err(5201): ... 1 more
02-24 17:37:05.755: W/System.err(5201): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
02-24 17:37:05.760: W/System.err(5201): at libcore.io.Posix.getaddrinfo(Native Method)
02-24 17:37:05.770: W/System.err(5201): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
02-24 17:37:05.770: W/System.err(5201): at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
02-24 17:37:05.770: W/System.err(5201): ... 18 more
02-24 17:37:05.770: W/System.err(5201): Caused by: libcore.io.ErrnoException: getaddrinfo failed: ENETUNREACH (Network is unreachable)
02-24 17:37:05.775: W/System.err(5201): ... 21 more##

最佳答案

在创建 http 请求之前是否检查网络连接,如下所示:

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();

关于java - Android 应用程序在重新启动时崩溃 java.net.UnknownHostException : Unable to resolve host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28697570/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com