Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol "Method"

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 ?

like image 649
fujitsu4 Avatar asked Aug 26 '15 14:08

fujitsu4


2 Answers

You are using

DownloadManager.Request.Method.GET

instead of

 com.android.volley.Request.Method.GET
like image 162
Vadim Caen Avatar answered Oct 17 '22 01:10

Vadim Caen


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,
like image 42
Rohit5k2 Avatar answered Oct 16 '22 23:10

Rohit5k2