[英]Why Android Studio prompt “Method doesn't override its superclass”?
I want to use volley to build http connection with authentication. 我想使用凌空来建立带有身份验证的http连接。 Following this answer I add the segment 在此答案之后,我添加了细分
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
String creds = String.format("%s:%s","USERNAME","PASSWORD");
String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
params.put("Authorization", auth);
return params;
}
in Anonymous Inner Class StringRequest
, and it looks like: 在Anonymous Inner Class StringRequest
,它看起来像:
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
//the segment below is what I add
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
String creds = String.format("%s:%s","USERNAME","PASSWORD");
String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
params.put("Authorization", auth);
return params;
}
//the segment above is what I add
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
However, IDE hints that getHeaders()
doesn't override its superclass. 但是,IDE暗示getHeaders()
不会覆盖其超类。
Why?I found that StringRequest extends class Request<String>
, and the latter does have a method called getHeaders()
. 为什么?我发现StringRequest扩展了类Request<String>
,后者确实有一个名为getHeaders()
的方法。
您正在重写Response.Listener<String>
的新实例内的public Map<String, String> getHeaders()
而不是Request<String>
并且Response.Listener<String>
没有这种方法(仅onResponse(String)
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.