Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Volley: Cannot resolve symbol Volley

I want to use Volley to send requests from my Android app.

I have included this in the build.gradle

dependencies {
    ...
   compile 'com.android.volley:volley:1.1.0'
}

I want to use:

requestQueue queue = Volley.newRequestQueue(this);

But neither requestQueue nor Volley can be resolved.

I have tried:

import com.android.volley;

But it also says that volley can't be resolved. I have done a gradle sync.

I have not downloaded anything. My understanding is that adding Volley to build.gradle takes the place of actually downloading the library?

like image 656
user984003 Avatar asked Jan 22 '18 15:01

user984003


3 Answers

The correct import is import com.android.volley.toolbox.Volley; (you can check the code here), and this has to be a Context object

like image 62
Blackbelt Avatar answered Nov 15 '22 05:11

Blackbelt


I ran into this problem today. Following works for me:

In Android Studio: Build -> Clean Project, and then Build -> Rebuild Project

like image 41
fishstick Avatar answered Nov 15 '22 04:11

fishstick


Thanks to Blackbelt's answer, I was able to import the following for Google's standard example https://developer.android.com/training/volley/simple.html

import com.android.volley.toolbox.Volley;
import com.android.volley.RequestQueue;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

The this in

RequestQueue queue = Volley.newRequestQueue(this);

became

RequestQueue queue = Volley.newRequestQueue(getContext());

also thanks to Blackbelt's answer. I had to play around with where I could call getContext() for my code. I ended up checking if the queue has already been instantiated inside my first request and set it if it hasn't.

like image 24
user984003 Avatar answered Nov 15 '22 04:11

user984003