I am working on login page when internet connection is off it shows me that incorrect email and password but when internet connection is on and i enter the wrong login email and password app stops. I don't know how to solve this please help me.
this is my code :
  @Override
    protected String doInBackground(String... params) {
        String login_email = params[0];
        String login_password = params[1];
        try {
            URL url = new URL(login_url);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            OutputStream outputStream = httpURLConnection.getOutputStream();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
            String data = URLEncoder.encode("login_email", "UTF-8") + "=" + URLEncoder.encode(login_email, "UTF-8") + "&" +
                    URLEncoder.encode("login_password", "UTF-8") + "=" + URLEncoder.encode(login_password, "UTF-8");
            bufferedWriter.write(data);
            bufferedWriter.flush();
            bufferedWriter.close();
            outputStream.close();
            InputStream inputStream = httpURLConnection.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            // String response = "";
            // JSONString = "";
            StringBuilder stringBuilder = new StringBuilder();
            while ((JSONString = bufferedReader.readLine()) != null) {
                // response += JSONString;
                stringBuilder.append(JSONString + "\n");
            }
            bufferedReader.close();
            inputStream.close();
            httpURLConnection.disconnect();
            return stringBuilder.toString().trim();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onPostExecute(String result) {
        loading.dismiss();
        if (result != null) {
            ParseJson(result);
        }
        else {
            Toast.makeText(Login.this, "Incorrect Email and Password", Toast.LENGTH_LONG).show();
        }
    }
LOGCAT:
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime: Process: com.example.mubbasher.howdy_sendgreetings, PID: 26814
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at android.os.AsyncTask$3.done(AsyncTask.java:300)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:841)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:  Caused by: java.lang.NullPointerException
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at libcore.net.UriCodec.encode(UriCodec.java:132)   
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.net.URLEncoder.encode(URLEncoder.java:57)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at com.example.mubbasher.howdy_sendgreetings.NewsFeedFragment$BackgroundSearch.doInBackground(NewsFeedFragment.java:109)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at com.example.mubbasher.howdy_sendgreetings.NewsFeedFragment$BackgroundSearch.doInBackground(NewsFeedFragment.java:89)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
05-02 23:01:19.103 26814-29816/com.example.mubbasher.howdy_sendgreetings E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:841) 
 
    