0

I code to send some message and email using HTTP post using Volley. when i run the emulator using Genymotion.Everything luking fine but i click the click button it show HTTP has been stopped. I am giving logcat picture Please click this Logcat picture to see Please help me what is wrong and how to resolve this problem

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    public static final String URL_CLICK = "http://www.careoservice.goyalsoftwares.com/feedback/add.php";
    public static final String KEY_MESSAGE = "message";
    public static final String KEY_EMAIL = "email";

    private EditText editTextMessages;
    private EditText editTextEmail;

    private Button buttonSend;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editTextEmail = (EditText) findViewById(R.id.editmsg);
        editTextEmail = (EditText) findViewById(R.id.editmail);

        buttonSend = (Button) findViewById(R.id.btnclk);

        buttonSend.setOnClickListener(this);
    }

    public void sendView() throws JSONException {
        final String message = editTextMessages.getText().toString().trim();
        final String email = editTextEmail.getText().toString().trim();

        StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_CLICK, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Toast.makeText(MainActivity.this,s, Toast.LENGTH_LONG).show();
            }
        },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put(KEY_MESSAGE, message);
                params.put(KEY_EMAIL, email);
                return params;
            }
        };
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }

    @Override
    public void onClick(View v) {
        if (v == buttonSend) {
            try {
                sendView();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Nitesh Khaitan
  • 191
  • 1
  • 2
  • 9
  • 1
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – OneCricketeer May 03 '16 at 17:35
  • 1
    Typo? `editTextEmail = (EditText) findViewById(R.id.editmsg); ` – OneCricketeer May 03 '16 at 17:37

1 Answers1

1

You are not initialazing the "editTextMessages", this is your null pointer exception.

AfroChase
  • 178
  • 2
  • 14