如何解决错误:找不到符号类RequestFinishedListener

时间:2018-03-08 03:58:55

标签: android request android-volley

在我的项目中,我正在使用排球包。但它显示在Volley中找不到符号类newRequestQueue。我该怎么解决呢

我已经导入了凌空包

import com.android.volley.RequestQueue.RequestFinishedListener; 

这是我的源代码

queue.addRequestFinishedListener(new RequestQueue.RequestFinishedListener<Object>() {
    @Override
    public void onRequestFinished(Request<Object> request) {
        // Start NewActivity.class
        Intent myIntent1 = new Intent(NewActivity.this, New2Activity.class);
        startActivity(myIntent1);
        Log.e("Error Response 2", "Request Finish");
    }
});

1 个答案:

答案 0 :(得分:2)

只需将以下行添加到您的应用级别build.gradle

即可
implementation 'com.android.volley:volley:1.1.0'

compile 'com.android.volley:volley:1.1.0'

然后这是可行的代码

    queue = Volley.newRequestQueue(getApplicationContext());
    queue.addRequestFinishedListener(new RequestQueue.RequestFinishedListener<Object>() {
        @Override
        public void onRequestFinished(Request<Object> request) {
            // Start NewActivity.class
            Intent myIntent1 = new Intent(MainActivity.this, ActivityTwo.class);
            startActivity(myIntent1);
            Log.e("Error Response 2", "Request Finish");
        }
    });