-2
我得到errorResponse而不是我应该得到的正常响应。我用简单的文本创建了一个简单的php文件,并将其放在wamp服务器上。我已经在浏览器上检查了它的工作正常,但不在此代码中。连接到WAMP时调用Android Volley onError
公共类MainActivity扩展AppCompatActivity {
Button button;
TextView textView;
String server_url="http://192.168.1.2/greetings.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= (Button) findViewById(R.id.bn);
textView= (TextView) findViewById(R.id.txt);
final RequestQueue requestQueue= Volley.newRequestQueue(MainActivity.this);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringRequest stringRequest=new StringRequest(Request.Method.POST, server_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
textView.setText(response);
requestQueue.stop();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
textView.setText("something wrong happened");
error.printStackTrace();
requestQueue.stop();
}
});
requestQueue.add(stringRequest);
}
});
}
}
什么样的错误? –
你为什么使用POST请求? –
[logcat会告诉你你的错误](http://stackoverflow.com/questions/23353173/uncomfort-myapp-has-stopped-how-can-i-solve-this)。请用它编辑你的问题。 –