Reputation: 29557
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?
Upvotes: 5
Views: 23794
Reputation: 29557
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.
Upvotes: 5
Reputation: 2274
I ran into this problem today. Following works for me:
In Android Studio: Build -> Clean Project
, and then Build -> Rebuild Project
Upvotes: 5