-2

I am getting errorResponse instead of the normal response i should have got. I have made a simple php file with a simple text and put it on the wamp server. And i have checked it on the browser it works fine but not in this code.

public class MainActivity extends 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);

            }
        });




    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

0

I'm not sure whether you are testing on emulator or android device. If you are using device then check
1. Your device and server is connected to same network (e.g: wifi router)
2. Off your windows firewall protection

Hope it might helps.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
ManishPrajapati
  • 459
  • 1
  • 5
  • 16
  • I am unable to access it using mobile network as well. tried turning off firewall protection as well but even that didn't work. – Avinash Chhabra Apr 09 '17 at 07:10