Android排球:无法解决符号排球

时间:2018-01-22 15:01:48

标签: android

我想使用Volley从我的Android应用程序发送请求。

我已将其包含在build.gradle

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

我想用:

requestQueue queue = Volley.newRequestQueue(this);

但是requestQueue和Volley都无法解决。

我试过了:

import com.android.volley;

但它也说凌空无法解决。我做了一个gradle同步。

我没有下载任何东西。我的理解是将buildley添加到build.gradle取代实际下载库?

4 个答案:

答案 0 :(得分:4)

正确导入为import com.android.volley.toolbox.Volley;(您可以检查代码here),this必须是Context对象

答案 1 :(得分:2)

感谢Blackbelt的回答,我能够为Google的标准示例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;

中的 this
RequestQueue queue = Volley.newRequestQueue(this);

成了

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

也要感谢Blackbelt的回答。我不得不玩我可以为我的代码调用getContext()的地方。我最后检查队列是否已在我的第一个请求中实例化,如果没有,则设置它。

答案 2 :(得分:0)

我今天遇到了这个问题。以下对我有用的作品:

在Android Studio中:先Build -> Clean Project,然后再Build -> Rebuild Project

答案 3 :(得分:0)

Hanumanjetlibrary.

  String url="http://rt.com/api/my.php";

ApicallAny.ApicallVolleywithoutParams(MainActivity.this,url, new ApicallAny.VolleyCallback() { @Override public void onSuccess(String result) {

      //  do stuff here  

    }

    @Override
    public void onError(String result) {
        //  do stuff here
    }
});

#withParams

Map params = new HashMap<>();

params.put("param1","val"); params.put("param2","valx");

String url="http://rt.com/api/my.php"; ApicallAny.ApicallVolleywithParams(MainActivity.this, url,params, new ApicallAny.VolleyCallback() { @Override public void onSuccess(String result) {

// do stuff here } @Override public void onError(String result) { // do stuff here } });
相关问题