title: No value for JSONObject Android
body: <p>I have been trying to solve <code>No value for JSONObject</code> error without any success. I am getting the JSON response and using a <code>try</code> block to create the JSONObject. I am testing for incorrect log in credentials which means the JSON reponse is like</p>
  
  <p><code>{"success":false,"messages":"Incorrect email\/password combination"}</code></p>
  
  <p>How can I get past this. Here's my code.</p>
  
  <pre><code>  try {
  
  
          JSONObject jObj = new JSONObject(response);
          boolean error = jObj.getBoolean("success");
  
         // Check for error node in json
          if (!error) {
               // user successfully logged in
               // Create login session
               mSessionManager.setLogin(true);
  
               // Now store the user in SQLite
               JSONObject user = jObj.getJSONObject("user");
               String firstName = user.getString("firstname");
               String lastName = user.getString("lastname");
               String email = user.getString("email");
               String created_at = user
                                  .getString("created_at");
               String uid = String.valueOf(user.getInt("user_id"));
  
               // Inserting row in users table
               mSQLiteHandler.addUser(firstName, lastName, email, uid, created_at);
  
               // Launch main activity
               Intent intent = new Intent(LoginActivity.this,
                                  Pedometer.class);
               startActivity(intent);
               finish();
  
            } else {
                // Error in login. Get the error message
                String errorMsg = jObj.getString("messages");
                Toast.makeText(getApplicationContext(),
                                  errorMsg, Toast.LENGTH_LONG).show();
            }
      } catch (JSONException e) {
            // JSON error
            Toast.makeText(getApplicationContext(),
             "Json error: " + e.getMessage(),
                              Toast.LENGTH_LONG).show();
      }
  </code></pre>
  
  <p>I have tried putting the block of code inside the if block inside <code>if(jObj.has("user")</code> but no error is being shown. The progress dialog shows and hides immediately</p>