无法解析符号 "Method"

Cannot resolve symbol "Method"

我试图在 Android 代码中执行一个简单的 GET 请求,我刚刚从 Volley 的官方网站复制了代码,但我收到一条错误消息:“无法解析符号 "Method" ”。

我的代码是这样的:

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();
        }
    });

// 将请求添加到 RequestQueue。 queue.add(字符串请求);

对于导入,我有这些行(我手动写的):

 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;

我试图包含以下行:“import com.android.volley.Request.Method;”但它没有改变任何东西。我仍然遇到同样的错误

我该如何解决这个问题?

您正在使用

DownloadManager.Request.Method.GET

而不是

 com.android.volley.Request.Method.GET

你用错了class

改变

StringRequest stringRequest = new StringRequest(DownloadManager.Request.Method.GET, url,

StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.GET, url,