NoSuchMethodError Request.setTag

时间:2017-10-27 08:37:16

标签: java android web-services android-volley

我正在尝试在注册过程中从服务器获得响应,但应用程序在尝试获取服务器消息时不断崩溃。下面是向AppControlla.java发出请求的代码部分,后者又将请求传递给服务器。

@Override
        public void onResponse(String response) {
            Log.d(TAG, "Register Response: " + response.toString());
            hideDialog();

这是AppControlla.java

import android.app.Application;
import android.text.TextUtils;

import com.app.myapp.JsonRequestActivity;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;

import static android.R.attr.tag;

public class AppController extends Application {

public static final String TAG = AppController.class.getSimpleName();

private RequestQueue mRequestQueue;

private static AppController mInstance;

@Override
public void onCreate() {
    super.onCreate();
    mInstance = this;
}

public static synchronized AppController getInstance() {
    return mInstance;
}

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
 }

    return mRequestQueue;
    }

public <T> void addToRequestQueue(Request<T> req, String tag) {
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);//crash occurs here
    getRequestQueue().add(req);

}

public <T> void addToRequestQueue(Request<T> req ) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
    if (mRequestQueue != null) {
        mRequestQueue.cancelAll(tag);
    }
}
}    
下面的

是logcat消息

java.lang.NoSuchMethodError: No virtual method setTag(Ljava/lang/Object;)Lcom/android/volley/Request; in class Lcom/android/volley/Request; or its super classes (declaration of 'com.android.volley.Request' appears in /data/app/com.fastchat-2/split_lib_dependencies_apk.apk:classes27.dex) at com.fastchat.AppController.addToRequestQueue(AppController.java:45) 

1 个答案:

答案 0 :(得分:0)

我终于解决了它。问题来自于我build.gradle中的一个依赖项,我刚刚删除了其中的一些,并且崩溃了。感谢你们的想法。