Cannot resolve symbol "Method"
Asked Answered
C

2

5

I tried to do a simple GET request in an Android Code, I just copied the code from the official site of Volley but i get an error saying that : " Cannot resolve symbol "Method" ".

My code is this :

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

// Add the request to the RequestQueue. queue.add(stringRequest);

For the imports, i have these lines (that i wrote manually):

 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;

I tried to include the line : " import com.android.volley.Request.Method;" but it doesn't change anything. I still got the same error

How can I fix this problem ?

Carousel answered 26/8, 2015 at 14:3 Comment(1)
if you import com.android.volley.Request.Method then simply put Request.Method.GET instead of DownloadManager.Request.MethodGuido
E
12

You are using

DownloadManager.Request.Method.GET

instead of

 com.android.volley.Request.Method.GET
Equator answered 26/8, 2015 at 14:9 Comment(0)
A
2

Your are using wrong class

Change

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

to

StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.GET, url,
Arand answered 26/8, 2015 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.