I had made application which takes name, contact number and another fields as input and saves that data on server in mysql database. This works fine when there is no validation in android app for input fields(EditText), but it gets fatal error when there is validation. Below is my code with validation and logcat. Again if I removes the validation code from activity then the data got successfully saed to server and I gots Json response for success. But with validation it is showing error, I don't know why is this happenning? Please help me.

```
.....
public static SharedPreferences sellcro;
    public static String name11;
    public static String mobile11;
    public static String weight11;
    public static String name111 = "";
    public static String mobile111 = "";
    public static String weight111 = "";

    JSONParser jsonParser = new JSONParser();
    EditText inputName;
    EditText inputMobile;
    EditText inputWeight;

private static final String TAG_SUCCESS = "success";
.....

inputName = (EditText) findViewById(R.id.editText1);
        inputMobile = (EditText) findViewById(R.id.editText2);
        inputWeight = (EditText) findViewById(R.id.editText3);
.....
btnCreateProduct.setOnClickListener....

name11 = inputName.getText().toString();
                if (!isValidName(name11)) {
                    inputName.setError("Please Enter Proper Name");
                }
                else{
                    name111 = "right";
                }

                mobile11 = inputMobile.getText().toString();
                if (!isValidMobile(mobile11)) {
                    inputMobile.setError("Please Enter 10 Digit Mobile Number");
                }
                else{
                    mobile111 = "right";
                }

                weight11 = inputWeight.getText().toString();
                if (!isValidWeight(weight11)) {
                    inputWeight.setError("Weight must be maximum of 9 character");
                }
                else{
                    weight111 = "right";
                } 
                 if(mobile111.equals("right") && weight111.equals("right") && name111.equals("right")){
new CreateNewProduct().execute();
            }else{}
}
});}

private boolean isValidWeight(String weight11) {
                // TODO Auto-generated method stub
                if(weight11 != null && weight11.length()>0 && weight11.length()<10){
                    return true;
                }
                return false;
            }

            private boolean isValidMobile(String mobile11) {
                // TODO Auto-generated method stub
                if(mobile11 != null && mobile11.length()>0 && mobile11.length()==10){
                    return true;
                }
                return false;
            }

            private boolean isValidName(String name11) {
                // TODO Auto-generated method stub
                if(name11 != null && name11.length()<60){
                    String name_pattern = "[a-zA-z]+([ '-][a-zA-Z]+)*";

                    Pattern pattern = Pattern.compile(name_pattern);
                    Matcher matcher = pattern.matcher(name11);
                    return matcher.matches();
                }
                return false;
            }  

class CreateNewProduct extends AsyncTask<...............
.......

protected String doInBackground(String... args) {
            ..........
             // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created product
                    // closing this screen
                } else {
                    // failed to create product
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }
...........

```

logcat:

```
02-25 05:28:04.103: D/OpenGLRenderer(2911): Render dirty regions requested: true
02-25 05:28:04.106: D/(2911): HostConnection::get() New Host Connection established 0xa5ce8ef0, tid 2911
02-25 05:28:04.114: D/Atlas(2911): Validating map...
02-25 05:28:04.153: D/libEGL(2911): loaded /system/lib/egl/libEGL_genymotion.so
02-25 05:28:04.153: D/(2911): HostConnection::get() New Host Connection established 0xa4d331e0, tid 2930
02-25 05:28:04.159: D/libEGL(2911): loaded /system/lib/egl/libGLESv1_CM_genymotion.so
02-25 05:28:04.171: D/libEGL(2911): loaded /system/lib/egl/libGLESv2_genymotion.so
02-25 05:28:04.178: I/OpenGLRenderer(2911): Initialized EGL, version 1.4
02-25 05:28:04.210: D/OpenGLRenderer(2911): Enabling debug mode 0
02-25 05:28:04.255: W/EGL_genymotion(2911): eglSurfaceAttrib not implemented
02-25 05:28:04.255: W/OpenGLRenderer(2911): Failed to set EGL_SWAP_BEHAVIOR on surface 0xb048c4e0, error=EGL_SUCCESS
02-25 05:28:07.584: W/EGL_genymotion(2911): eglSurfaceAttrib not implemented
02-25 05:28:07.584: W/OpenGLRenderer(2911): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa4e56060, error=EGL_SUCCESS
02-25 05:28:24.934: W/EGL_genymotion(2911): eglSurfaceAttrib not implemented
02-25 05:28:24.934: W/OpenGLRenderer(2911): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa4e352e0, error=EGL_SUCCESS
02-25 05:28:25.532: E/JSON Parser(2911): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
02-25 05:28:25.544: E/AndroidRuntime(2911): FATAL EXCEPTION: AsyncTask #1
02-25 05:28:25.544: E/AndroidRuntime(2911): Process: com.creatorscorp.krushidhan, PID: 2911
02-25 05:28:25.544: E/AndroidRuntime(2911): java.lang.RuntimeException: An error occured while executing doInBackground()
02-25 05:28:25.544: E/AndroidRuntime(2911):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at java.lang.Thread.run(Thread.java:818)
02-25 05:28:25.544: E/AndroidRuntime(2911): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
02-25 05:28:25.544: E/AndroidRuntime(2911):     at com.creatorscorp.krushidhan.SellYourCrops$CreateNewProduct.doInBackground(SellYourCrops.java:307)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at com.creatorscorp.krushidhan.SellYourCrops$CreateNewProduct.doInBackground(SellYourCrops.java:1)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-25 05:28:25.544: E/AndroidRuntime(2911):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-25 05:28:25.544: E/AndroidRuntime(2911):     ... 4 more
02-25 05:28:25.840: W/EGL_genymotion(2911): eglSurfaceAttrib not implemented
02-25 05:28:25.841: W/OpenGLRenderer(2911): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa1361360, error=EGL_SUCCESS
02-25 05:28:26.330: E/WindowManager(2911): android.view.WindowLeaked: Activity com.creatorscorp.krushidhan.SellYourCrops has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{110dbf2c V.E..... R......D 0,0-1026,348} that was originally added here
02-25 05:28:26.330: E/WindowManager(2911):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
02-25 05:28:26.330: E/WindowManager(2911):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
02-25 05:28:26.330: E/WindowManager(2911):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
02-25 05:28:26.330: E/WindowManager(2911):  at android.app.Dialog.show(Dialog.java:298)
02-25 05:28:26.330: E/WindowManager(2911):  at com.creatorscorp.krushidhan.SellYourCrops$CreateNewProduct.onPreExecute(SellYourCrops.java:280)
02-25 05:28:26.330: E/WindowManager(2911):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
02-25 05:28:26.330: E/WindowManager(2911):  at android.os.AsyncTask.execute(AsyncTask.java:535)
02-25 05:28:26.330: E/WindowManager(2911):  at com.creatorscorp.krushidhan.SellYourCrops$5.onClick(SellYourCrops.java:221)
02-25 05:28:26.330: E/WindowManager(2911):  at android.view.View.performClick(View.java:4756)
02-25 05:28:26.330: E/WindowManager(2911):  at android.view.View$PerformClick.run(View.java:19749)
02-25 05:28:26.330: E/WindowManager(2911):  at android.os.Handler.handleCallback(Handler.java:739)
02-25 05:28:26.330: E/WindowManager(2911):  at android.os.Handler.dispatchMessage(Handler.java:95)
02-25 05:28:26.330: E/WindowManager(2911):  at android.os.Looper.loop(Looper.java:135)
02-25 05:28:26.330: E/WindowManager(2911):  at android.app.ActivityThread.main(ActivityThread.java:5221)
02-25 05:28:26.330: E/WindowManager(2911):  at java.lang.reflect.Method.invoke(Native Method)
02-25 05:28:26.330: E/WindowManager(2911):  at java.lang.reflect.Method.invoke(Method.java:372)
02-25 05:28:26.330: E/WindowManager(2911):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-25 05:28:26.330: E/WindowManager(2911):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-25 05:28:27.336: I/Process(2911): Sending signal. PID: 2911 SIG: 9

```

JSonParser:

```
public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method,
            List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if(method == "POST"){
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            }else if(method == "GET"){
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}

```