Android Volley: Cannot resolve symbol Volley
Asked Answered
P

3

5

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?

Parashah answered 22/1, 2018 at 15:1 Comment(0)
E
8

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

Eleanoraeleanore answered 22/1, 2018 at 15:7 Comment(4)
Perfect, thank you! This will also help me with the other import statements that I need.Parashah
Do you know how to import StringRequest needed in Google's example: developer.android.com/training/volley/simple.htmlParashah
import com.android.volley.toolbox.StringRequest;Eleanoraeleanore
I found I had to restart Android Studio after adding it to the dependencies in the gradle file. Nothing else worked until I restarted.Brackett
P
5

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.

Parashah answered 22/1, 2018 at 16:23 Comment(0)
S
5

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

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

Stenger answered 25/11, 2019 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.