title: Android app works for 1 type of value of Json but not another
body: <p>I'm building an android application, and whenever I send a get request to my server it returns Jsons like:</p>
  
  <pre><code>{
      "status":"error",
      "error":"Username already exists."
  }
  </code></pre>
  
  <p>or when the user doesn't exists and so does the email:</p>
  
  <pre><code>{
      "status":"ok",
      "cookie":"test16|1519060288|Jf8jEzJe8C7JJWmAxW6ViJbLKgsY1XuCH0OStT38vG2|d6489d623438870a08da717cc6f1851496c2e1e7c45557da7c8df8d1f80f1db4",
      "user_id":285
  }
  </code></pre>
  
  <p>The thing is, for the second Json, everything works Perfectly, the user gets an email, the app does as it should.
  But when you try to register with an existing username, eveything crashes,
  and from my logcat, I found that it crashes in the line of BufferReader declaration, or in this line : <code>if (responseCode == HttpsURLConnection.HTTP_OK)</code>, if I choose to include it.
  What reason on earth could be that my code accepts one type of Jsons where <code>"status" = "ok"</code>, and not when it equals "error"?</p>
  
  <p>this is my asynctask:</p>
  
  <pre><code>    public class Register extends AsyncTask&lt;String, Void, RegisterData&gt; {
  
  
      @Override
      protected void onPreExecute() {
          p= ProgressDialog.show(SignUpActivity.this,getString(R.string.Authenticating),getString(R.string.loadingPleaseWait),true);
          p.setCancelable(true);
          p.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
          p.setMessage(getString(R.string.loadingDotDotDot));
          p.show();
  
      }
  
      @Override
      protected RegisterData doInBackground(String... params)
      {
          String str=params[0];
          String res=performPostCall(str);
          Log.d("ress", res);
          if (Response.matches(""))
          {
              register.cancel(true);
          }
          RegisterData regi = null;
          try
          {
  
              JSONObject json_data = new JSONObject(res);
              String Status = json_data.getString("status");
              String error = "null";
              if (Status.equals("ok"))
                  error = "null";
              else
                  error= json_data.getString("error");
              Log.d("coo", error);
              regi= new RegisterData(Status,error);
              Log.d("stat", regi.getStatus());
          }
          catch(JSONException e)
          {
  
          }
          Log.d("aa", res);
          return regi;
      }
  
      @Override
      protected void onPostExecute(RegisterData result) {
          Log.d("stat2", result.getStatus());
  
          if (result.getStatus().equals("ok")) {
              check = true;
              Toast.makeText(SignUpActivity.this, R.string.SuccessfulLogin, Toast.LENGTH_LONG).show();
              finish();
          }
          else
          {
              check = false;
              Toast.makeText(SignUpActivity.this, R.string.WrongUserOrPass, Toast.LENGTH_LONG).show();
          }
          p.dismiss();
  
      }
  }
  </code></pre>
  
  <p>this is the class that performs the http request:</p>
  
  <pre><code>    public String performPostCall(String requestURL) {
  
      URL url;
      Log.d("nugi", "Got Here 1");
      String response = "";
      try {
          String str=getPostDataString();
          Log.d("nugi", "Got Here 2");
  
          url = new URL(requestURL+str);
          Log.d("nugi", url.toString());
  
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setReadTimeout(15000);
          conn.setConnectTimeout(15000);
          conn.setRequestMethod("GET");
          conn.setDoInput(true);
          conn.setDoOutput(true);
  
          int responseCode=conn.getResponseCode();
          if (responseCode == HttpsURLConnection.HTTP_OK) {
              Log.d("nugi", "Got Here 3");
              String line;
              BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream(), "iso-8859-1"));
          Log.d("nugi", "Got Here 4");
          while ((line=br.readLine()) != null) {
                  response+=line;
                  Log.d("nugi", "Got Here 5");
              }
          Log.d("nugi", response);
  
          Response = response;
          }
          /*else {
              response="";
              Response = response;
  
          }*/
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      return response;
  }
  </code></pre>
  
  <p>this is my logcat error:</p>
  
  <blockquote>
    <p>02-05 17:24:28.075 5378-5394/com.example.negev.peulibraryv201 E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab38aea0
    02-05 17:24:28.082 5378-5394/com.example.negev.peulibraryv201 E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab38a5e0
    02-05 17:24:28.332 5378-5378/com.example.negev.peulibraryv201 E/WindowManager: android.view.WindowLeaked: Activity com.example.negev.peulibraryv201.SignUpActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{bd0880e V.E...... R......D 0,0-729,322} that was originally added here
                                                                                       at android.view.ViewRootImpl.(ViewRootImpl.java:368)
                                                                                       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
                                                                                       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
                                                                                       at android.app.Dialog.show(Dialog.java:319)
                                                                                       at android.app.ProgressDialog.show(ProgressDialog.java:116)
                                                                                       at android.app.ProgressDialog.show(ProgressDialog.java:99)
                                                                                       at com.example.negev.peulibraryv201.SignUpActivity$Register.onPreExecute(SignUpActivity.java:156)
                                                                                       at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:604)
                                                                                       at android.os.AsyncTask.execute(AsyncTask.java:551)
                                                                                       at com.example.negev.peulibraryv201.SignUpActivity.onClick(SignUpActivity.java:87)
                                                                                       at android.view.View.performClick(View.java:5198)
                                                                                       at android.view.View$PerformClick.run(View.java:21147)
                                                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                       at android.os.Looper.loop(Looper.java:148)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)</p>
  </blockquote>
  
  <p>Thank you!</p>