我刚开始使用Android Studio并制作了一个小应用程序。我的问题是我无法连接到网站。我已经为我的项目添加了凌空来处理响应。我搜索了其他类似的问题,但所有的回复建议添加一个权限清单文件(我已经拥有它)。
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
发出请求后,我收到错误消息:java.net.UnknownHostException: Unable to resolve host "url goes here": No address associated with hostname
网址有效,我尝试从浏览器访问它
我该怎么办?
编辑
StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
{
@Override public void onResponse(String response)
{
Log.e("resp", response);
Toast.makeText(context.getApplicationContext(), response, Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override public void onErrorResponse(VolleyError error)
{
Log.d("error", error.getMessage());
}
});
VolleyCore.getInstance(context).addToRequestQueue(request);