Emulator错误-com.android.volley.NoConnectionError:java.net.UnknownHostException:无法解析主机
我有一个基本的截击请求,每次我在模拟器上尝试应用程序时都会抛出这个错误,但在实际设备上工作正常,我已经在清单中添加了“网络安全配置”,我仍然会收到错误Emulator错误-com.android.volley.NoConnectionError:java.net.UnknownHostException:无法解析主机,java,android,request,android-volley,Java,Android,Request,Android Volley,我有一个基本的截击请求,每次我在模拟器上尝试应用程序时都会抛出这个错误,但在实际设备上工作正常,我已经在清单中添加了“网络安全配置”,我仍然会收到错误 private static final String url = "https://pixabay.com/api/?key=5303976-fd6581ad4ac165d1b75cc15b3&q=kitten&image_type=photo&pretty=true"; Cache cache =
private static final String url = "https://pixabay.com/api/?key=5303976-fd6581ad4ac165d1b75cc15b3&q=kitten&image_type=photo&pretty=true";
Cache cache = new DiskBasedCache(getCacheDir(), 1024 *1024);
Network network = new BasicNetwork(new HurlStack());
mRequestQueue = new RequestQueue(cache, network);
mRequestQueue.start();
StringRequest request = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e(TAG, "Response: " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mRequestQueue.add(request);
private静态最终字符串url=”https://pixabay.com/api/?key=5303976-fd6581ad4ac165d1b75cc15b3&q=kitten&image_type=photo&pretty=true”;
Cache Cache=新的DiskBasedCache(getCacheDir(),1024*1024);
网络=新的基本网络(new HurlStack());
mRequestQueue=新请求队列(缓存、网络);
mRequestQueue.start();
StringRequest=newStringRequest(url,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
Log.e(标签“响应:”+响应);
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
错误。printStackTrace();
}
});
mRequestQueue.add(请求);
网络安全配置
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
显示
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>