[Solved] java.lang.NullPointerException while fetching value from EditText [duplicate]


You can’t just instantiate your Activity and access the TextView members on it. This doesn’t make any sense:

indoor_patient ins=new indoor_patient();    
String webUrl = "http://10.0.3.2:8084/data_web/indoorPatient.jsp?sr_no="
        + ins.sr_no.getText().toString()

Instead you could figure out what your webUrl is in your onClick() method and pass in the complete URL as a parameter to the AsyncTask:

submit.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        String webUrl = "http://10.0.3.2:8084/data_web/indoorPatient.jsp?sr_no="
                + ins.sr_no.getText().toString()
                + ""
                + ins.patient_name.getText().toString()
                + ""
                + ins.consultant_name.getText().toString()
                + ""
                + ins.ref_dr.getText().toString()
                + ""
                + ins.department.getText().toString()
                + ""
                + ins.rel_name.getText().toString()
                + ""
                + ins.rel_no.getText().toString()
                + ""
                + ins.arr_date.getText().toString()
                + ""
                + ins.arr_time.getText().toString() + "&submit=Submit";
        new dbwork().execute(webUrl);
    }
});

Then change your AsyncTask to something like this:

public class dbwork extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... params) {
        String webUrl = params[0];
        // TODO Auto-generated method stub
        StringBuffer strbuffer=new StringBuffer("");
        // ...

solved java.lang.NullPointerException while fetching value from EditText [duplicate]