Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 694
user7377283 Avatar asked Jan 05 '17 04:01

user7377283


1 Answers

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.

like image 83
Daniel Zhang Avatar answered Oct 20 '22 16:10

Daniel Zhang