title: JSONException: No value for
body: <p>Getting the following error in my code, I believe it is not reading my JSON correctly and I don't understand why, it was working fine before I made a few changes last week but I forgot what changes I made.</p>
  
  <blockquote>
    <p>W/System.err(1551): org.json.JSONException: No value for uid</p>
  </blockquote>
  
  <p>Basically, this program is to login with a username/pass and pass the data from a MySQL database using JSON parsing into the next activity. On pressing the login button, It sends an HTTP request to a PHP page which validates in MySQL and returns a JSON string (array) of the users data to the next activity.</p>
  
  <p>This activity shows up, but it's blank, and it should be displaying all the persons info in different TextViews but it's not.</p>
  
  <p>Here is a JSON output example:</p>
  
  <blockquote>
    <p>{"users":[{"fullname":"Adam","displayname":"adamator","email":"123","password":"123","created_at":"2013-11-30 11:20:31","updated_at":"2013-11-30 11:34:08"}]}</p>
  </blockquote>
  
  <p>So what I would like to do is to display what is in the JSON object in the logcat or in a pop up message or something so that I can see if my JSON parser is working properly. How can I do this? Or if someone can see a problem in my code that I am missing, that would be even better.</p>
  
  <p>Here is my Homepage.java</p>
  
  <pre><code>public class Homepage extends Activity {
  
      // URL to get JSON Arrays
      public static String url = "http://10.0.2.2/android/SQL.php?username='";
      public static String usernamefromlogin;
      public static TextView errorchecking;
  
      // JSON Node Names
      private static final String TAG_USER = "users";
      private static final String TAG_ID = "uid";
      private static final String TAG_NAME = "fullname";
      private static final String TAG_DISPLAY = "displayname";
      private static final String TAG_EMAIL = "email";
      private static final String TAG_PW = "password";
      private static final String TAG_CREATED = "created_at";
      private static final String TAG_UPDATED = "updated_at";
  
      JSONArray user = null;
  
      @Override
      public void onBackPressed() {
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.reshomepage);
  
          // Get login name from EditText in login screen and concatenate it to
          // PHP user-name for _GET command in 3 steps.
          // Step 1: Get intent from previous activity
          Intent intent = getIntent();
          getIntent().getExtras();
  
          // Step 2: convert intent (intent) to string called "usernamefromlogin"
          // //error checking in log cat to see value of "usernamefromlogin"
          usernamefromlogin = intent.getExtras().getString("username2");
          Log.d("log of usernamefromlogin", usernamefromlogin);
  
          // Step 3: take the string "url" and add string "usernamefromlogin"
          // after it
          String url5 = url.concat(usernamefromlogin);
          String url6 = url5.concat("'");
          // find TextView "errorchecking" and send the string "url6" to it so it
          // can display in log cat
          Log.d("log of URL6 in it's final state", url6);
  
          // Creating new JSON Parser
          JSONParser jParser = new JSONParser();
  
          // Getting JSON from URL from the final string "url6"
          JSONObject json = jParser.getJSONFromUrl(url6);
          // Logcat check value for TAG_USER
  
          try {
              // Getting JSON Array
  
              user = json.getJSONArray(TAG_USER);
              JSONObject c = user.getJSONObject(0);
  
              // Storing JSON item in a String Variable
              String uid = c.getString(TAG_ID);
              String name = c.getString(TAG_NAME);
              String display = c.getString(TAG_DISPLAY);
              String email = c.getString(TAG_EMAIL);
              String pw = c.getString(TAG_PW);
              String created = c.getString(TAG_CREATED);
              String updated = c.getString(TAG_UPDATED);
  
              // Importing TextView
              final TextView uid1 = (TextView) findViewById(R.id.tvuid);
              final TextView name1 = (TextView) findViewById(R.id.tvfullname);
              final TextView display1 = (TextView) findViewById(R.id.tvdisplayname);
              final TextView email1 = (TextView) findViewById(R.id.tvemail);
              final TextView pw1 = (TextView) findViewById(R.id.tvpassword);
              final TextView created1 = (TextView) findViewById(R.id.tvcreated_at);
              final TextView updated1 = (TextView) findViewById(R.id.tvupdated_at);
  
              ImageView imgView;
              imgView = (ImageView) findViewById(R.id.image);
              imgView.setImageResource(R.drawable.icon);
  
              // Set JSON Data in its respectable TextView
              uid1.setText(uid);
              name1.setText(name);
              display1.setText(display);
              email1.setText(email);
              pw1.setText(pw);
              created1.setText(created);
              updated1.setText(updated);
  
              // print error if applicable.
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>JSONParser.java  </p>
  
  <pre><code>package com.sencide;
  
  import learn2crack.jsonparsing.library.JSONParser;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class Homepage extends Activity {
  
      // URL to get JSON Arrays
      public static String url = "http://10.0.2.2/android/SQL.php?username='";
      public static String usernamefromlogin;
      public static TextView errorchecking;
  
      // JSON Node Names
      private static final String TAG_USER = "users";
      private static final String TAG_ID = "uid";
      private static final String TAG_NAME = "fullname";
      private static final String TAG_DISPLAY = "displayname";
      private static final String TAG_EMAIL = "email";
      private static final String TAG_PW = "password";
      private static final String TAG_CREATED = "created_at";
      private static final String TAG_UPDATED = "updated_at";
  
      JSONArray user = null;
  
      @Override
      public void onBackPressed() {
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.reshomepage);
  
          // Get login name from EditText in login screen and concatenate it to
          // PHP user-name for _GET command in 3 steps.
          // Step 1: Get intent from previous activity
          Intent intent = getIntent();
          getIntent().getExtras();
  
          // Step 2: convert intent (intent) to string called "usernamefromlogin"
          // //error checking in log cat to see value of "usernamefromlogin"
          usernamefromlogin = intent.getExtras().getString("username2");
          Log.d("log of usernamefromlogin", usernamefromlogin);
  
          // Step 3: take the string "url" and add string "usernamefromlogin"
          // after it
          String url5 = url.concat(usernamefromlogin);
          String url6 = url5.concat("'");
          // find TextView "errorchecking" and send the string "url6" to it so it
          // can display in log cat
          Log.d("log of URL6 in it's final state", url6);
  
          // Creating new JSON Parser
          JSONParser jParser = new JSONParser();
  
          // Getting JSON from URL from the final string "url6"
          JSONObject json = jParser.getJSONFromUrl(url6);
          // Logcat check value for TAG_USER
  
          try {
              // Getting JSON Array
  
              user = json.getJSONArray(TAG_USER);
              JSONObject c = user.getJSONObject(0);
  
              // Storing JSON item in a String Variable
              String uid = c.getString(TAG_ID);
              String name = c.getString(TAG_NAME);
              String display = c.getString(TAG_DISPLAY);
              String email = c.getString(TAG_EMAIL);
              String pw = c.getString(TAG_PW);
              String created = c.getString(TAG_CREATED);
              String updated = c.getString(TAG_UPDATED);
  
              // Importing TextView
              final TextView uid1 = (TextView) findViewById(R.id.tvuid);
              final TextView name1 = (TextView) findViewById(R.id.tvfullname);
              final TextView display1 = (TextView) findViewById(R.id.tvdisplayname);
              final TextView email1 = (TextView) findViewById(R.id.tvemail);
              final TextView pw1 = (TextView) findViewById(R.id.tvpassword);
              final TextView created1 = (TextView) findViewById(R.id.tvcreated_at);
              final TextView updated1 = (TextView) findViewById(R.id.tvupdated_at);
  
              ImageView imgView;
              imgView = (ImageView) findViewById(R.id.image);
              imgView.setImageResource(R.drawable.icon);
  
              // Set JSON Data in its respectable TextView
              uid1.setText(uid);
              name1.setText(name);
              display1.setText(display);
              email1.setText(email);
              pw1.setText(pw);
              created1.setText(created);
              updated1.setText(updated);
  
              // print error if applicable.
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>