import com.amazonaws.services.dynamodbv2.document.DynamoDB; the document part of the import cannot be resolved

6.1k views Asked by At

I tried to update my dynamodb using aws but I am not able to create a dynamodb object or a table object as the import com.amazonaws.services.dynamodbv2.**document**.* does not register document but it reads all the other imports:

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ListTablesResult;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.TableDescription;

Below is the full class I am using:

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec;
import com.amazonaws.services.dynamodbv2.document.utils.ValueMap;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.TableCollection;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec;
import com.amazonaws.services.dynamodbv2.document.utils.ValueMap;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.TableCollection;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ListTablesResult;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.TableDescription;

public class LoadingPage extends AppCompatActivity {
    static AmazonDynamoDBClient dynamoDB;
    LocationManager locationmanager;
    private TrackGPS gps;
    double longitude;
    double latitude;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading_page);
        gps = new TrackGPS(LoadingPage.this);
        DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient(
                new ProfileCredentialsProvider()));

        Table table = dynamoDB.getTable("ProductCatalog");

        Map<String, String> expressionAttributeNames = new HashMap<String, String>();
        expressionAttributeNames.put("#A", "Authors");
        expressionAttributeNames.put("#P", "Price");
        expressionAttributeNames.put("#I", "ISBN");

        Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
        expressionAttributeValues.put(":val1",
                new HashSet<String>(Arrays.asList("Author YY","Author ZZ")));
        expressionAttributeValues.put(":val2", 1);   //Price

        UpdateItemOutcome outcome =  table.updateItem(
                "Id",          // key attribute name
                101,           // key attribute value
                "add #A :val1 set #P = #P - :val2 remove #I", 
                expressionAttributeNames,
                expressionAttributeValues);
2

There are 2 answers

0
Liv On

I'm assuming you probably tried this already, but it worked for me so I'm going to mention it anyway: I made sure that the AWS SDK for Java library had been added and then I refreshed the project. Now all is working!

I closed my project down and reopened it many times with no success, but refreshing the project did the trick. Good luck.

0
Daniel Zhang On

I had a similar problem and what I've learned is that the availability of, and/or source repositories for, packages can change over time.Therefore, if an import cannot be resolved, the following procedure may help.

  1. Identify the package that supplies the dependency.
  2. Locate a source for the package.
  3. Configure the source with Gradle or Maven.

For my answer, I verified your desired imports against com.amazonaws:DynamoDBLocal:1.11.477 under Kotlin.

From the artifact page at MVNRepository, I selected View All.

This led me to a repository source with the following URL:

https://repository.mulesoft.org/nexus/content/repositories/public/com/amazonaws/DynamoDBLocal/1.11.477/

Since I was using Kotlin, I added the corresponding repository data to repositories in my build.gradle.kts for Gradle.

// Local DynamoDB.

repositories {
    maven(url = "https://repository.mulesoft.org/nexus/content/repositories/public")
}

dependencies {
    implementation ("com.amazonaws:DynamoDBLocal:1.11.477")
}

These imports, for the non-local case, can also be satisfied from the package at:

http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-dynamodb/1.11.564/

Therefore, the following entries also work:

// Remote DynamoDB.

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.amazonaws:aws-java-sdk-dynamodb:1.11.564")
}

After configuring my project for either the local or remote versions, I was able to verify that all of your imports that include "document" were available.