fuj*_*su4 5 android android-studio android-volley
我试图在Android代码中做一个简单的GET请求,我只是从Volley的官方网站复制了代码,但我得到一个错误说:"无法解析符号"方法"".
我的代码是这样的:
public void onReceive(final Context context, Intent intent) {
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(context);
String url = ***** ; // my URL
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(DownloadManager.Request.Method.GET, url,
new Response.Listener<String>() { //the error is in THIS line
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
Toast.makeText(context, "Response is: " + response.substring(0,500), Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, "error", Toast.LENGTH_LONG).show();
}
});
Run Code Online (Sandbox Code Playgroud)
//将请求添加到RequestQueue.queue.add(stringRequest);
对于导入,我有这些行(我手动编写):
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
Run Code Online (Sandbox Code Playgroud)
我试图包括这一行:"import com.android.volley.Request.Method;" 但它没有改变任何东西.我仍然有同样的错误
我该如何解决这个问题?
Vad*_*aen 10
您正在使用
DownloadManager.Request.Method.GET
Run Code Online (Sandbox Code Playgroud)
代替
com.android.volley.Request.Method.GET
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7750 次 |
| 最近记录: |