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?
The correct import is import com.android.volley.toolbox.Volley;
(you can check the code here), and this
has to be a Context
object
I ran into this problem today. Following works for me:
In Android Studio: Build -> Clean Project
, and then Build -> Rebuild Project
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With