-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)。請用它編輯你的問題。 –