title: NullPointer Exception Error when i am trying to read from AWS Dyanamodb in Android?
body: <p>I am trying to load Phone Number as a string from Dynamodb but it is showing NullPointer Error</p>
  
  <p>Here is My Activity Code in which i am trying to Log the data </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class TokenActivity extends Activity {
      DynamoDBMapper dynamoDBMapper;
      @Override
      public void onCreate(final Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_hello_token);
  
          AWSMobileClient.getInstance().initialize(this).execute();
          AWSCredentialsProvider credentialsProvider = AWSMobileClient.getInstance().getCredentialsProvider();
          AWSConfiguration configuration = AWSMobileClient.getInstance().getConfiguration();
  
  
          AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient(credentialsProvider);
  
          this.dynamoDBMapper = DynamoDBMapper.builder()
                  .dynamoDBClient(dynamoDBClient)
                  .awsConfiguration(configuration)
                  .build();
  
  
          readName();
      }
  
      public void readName() {
          new Thread(new Runnable() {
              @Override
              public void run() {
  
                  LoginCredentialsDO newsItem = dynamoDBMapper.load(
                          LoginCredentialsDO.class,
                          "userId",
                          "Phone Number");
                  // Item read
                    Log.d("News Item:", newsItem.getPhoneNumber());
              }
          }).start();
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>and LoginCredentialsDO containing methods to retrieve data from Database.</p>
  
  <blockquote>
    <p>Blockquote</p>
  </blockquote>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class LoginCredentialsDO {
      private String _userId;
      private String _phoneNumber;
      private String _emailId;
      private String _name;
  
      @DynamoDBHashKey(attributeName = "userId")
      @DynamoDBAttribute(attributeName = "userId")
      public String getUserId() {
          return _userId;
      }
  
      public void setUserId(final String _userId) {
          this._userId = _userId;
      }
      @DynamoDBRangeKey(attributeName = "Phone Number")
      @DynamoDBAttribute(attributeName = "Phone Number")
      public String getPhoneNumber() {
          return _phoneNumber;
      }
  
      public void setPhoneNumber(final String _phoneNumber) {
          this._phoneNumber = _phoneNumber;
      }
      @DynamoDBAttribute(attributeName = "Email Id")
      public String getEmailId() {
          return _emailId;
      }
  
      public void setEmailId(final String _emailId) {
          this._emailId = _emailId;
      }
      @DynamoDBAttribute(attributeName = "Name")
      public String getName() {
          return _name;
      }
  
      public void setName(final String _name) {
          this._name = _name;
      }
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am getting NullPointer Exception Error</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.....LoginCredentialsDO.getPhoneNumber()' on a null object reference
          at com......TokenActivity$4.run(TokenActivity.java:153)
          at java.lang.Thread.run(Thread.java:764)</code></pre>
  </div>
  </div>
  </p>
  
  <p>Can anyone explain why I am getting null point error as I have already defined all the variables and the database item which I am accessing is also not null?</p>