【发布时间】:2018-09-02 09:06:17
【问题描述】:
大家好,我使用的是 Android Volley,版本 1.1.1。当它是一个 GET 请求时,该项目会迅速运行,但是一旦我添加参数并将其转换为 POST 请求(就像我在互联网上找到的所有示例一样)它不想运行并给我三个错误:
error no. 1" There is no applicable constructor to '(into, java.lang.String, com.vm.okone.MainActivity.(anonymous),com.vm.okone.MainActivity.(anonymous))', error no. 2 " method onResponse does not override method from its superclass, error no. 3 " method onErrorResponse does not override method from its superclass.
这是我的 POST 代码
//TextView
final TextView mTextView = (TextView)findViewById(R.id.serverResp);
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
//url
String url = "http://127.0.0.1:8080/index.jsp";
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the response string.
mTextView.setText(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText("That didn't work!");
}
}) {
//adding parameters to the request
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("name", "asdf");
params.put("email", "qwerty");
return params;
}
};
// Add the request to the RequestQueue.
queue.add(stringRequest);
【问题讨论】:
-
它仍然给我同样的错误,我开始认为它与上下文有关,但现在我不知道如何应用它。
-
这取决于您在哪里使用这些代码?这很奇怪,因为我这边的一切看起来都很正常。
-
您可以在文件顶部发布您的导入语句吗?
-
导入android.os.Bundle;导入android.app.Activity;导入 android.widget.TextView;导入 java.util.Map;导入 java.util.HashMap;导入 com.android.volley.Request;导入 com.android.volley.Response;导入 com.android.volley.RequestQueue;导入 com.android.volley.VolleyError;导入 com.android.volley.AuthFailureError;导入 com.android.volley.toolbox.Volley;导入 com.android.volley.toolbox.StringRequest;