S bruce
S bruce

Reputation: 1514

Amazon DynamoDB PaginatedQueryList null object reference error

I get a null object reference error when I try to Query data from my Amazon DynamoDB table like this:

 mapper = new DynamoDBMapper(ddbClient);

 DataMapperClass dataMapperClass = new DataMapperClass();
 dataMapperClass.setHash("theHashValueIset");

 String queryString = String.valueOf("theRangeValueIset");
 
 Condition rangeKeyCondition = new Condition()
     .withComparisonOperator(ComparisonOperator.BEGINS_WITH.toString())
     .withAttributeValueList(new AttributeValue().withS(queryString.toString()));

 DynamoDBQueryExpression <DataMapperClass> queryExpression = new DynamoDBQueryExpression<DataMapperClass>()
     .withHashKeyValues(dataMapperClass)
     .withRangeKeyCondition("rangeAttributeOnTable", rangeKeyCondition)
     .withConsistentRead(false);

 PaginatedQueryList<DataMapperClass> result = mapper.query(DataMapperClass.class, queryExpression);

My DataMapperClass.class:

  @DynamoDBTable(tableName = "myTableName")
  public class DataMapperClass {

  private String hash;//based on a set of categories I chose
  private String objectID; //auto generated 


  //Hash
  @DynamoDBHashKey(attributeName = "hashNameOnMyTable")
  public String getHash() { return hash; }
  public void setHash(String hash) { this.hash = hash;}


  //ObjectID
  @DynamoDBRangeKey(attributeName = "rangeAttributeOnTable")
  @DynamoDBAutoGeneratedKey
  public String getObjectID() {return objectID;}
  public void setObjectID(String objectID) { this.objectID = objectID;  }

  /* other @DynamoDBAttribute*/

  }

How can I solve this error I get on the "PaginatedQueryList" code line :

Attempt to invoke interface method 'com.amazonaws.services.dynamodbv2.model.QueryResult com.amazonaws.services.dynamodbv2.AmazonDynamoDB.query(com.amazonaws.services.dynamodbv2.model.QueryRequest)' on a null object reference

Upvotes: 0

Views: 1088

Answers (1)

S bruce
S bruce

Reputation: 1514

Problem solved!

I realised I did not do this in my onCreate():

   ddbClient = new AmazonDynamoDBClient(identityManager.getCredentialsProvider());

Upvotes: 0

Related Questions