我尝试使用aws更新我的dynamodb,但我无法创建一个dynamodb对象或一个表对象,因为import com.amazonaws.services.dynamodbv2.**document**.*
没有注册文档,但它读取所有其他导入:
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;
以下是我正在使用的完整课程:
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);
答案 0 :(得分:1)
我遇到了类似的问题,并且我了解到软件包的可用性和/或源存储库会随着时间的推移而变化。因此,如果无法解决导入问题,则以下过程可能会有所帮助。
对于我的回答,我在Kotlin下针对com.amazonaws:DynamoDBLocal:1.11.477
验证了您想要的导入。
我从artifact page at MVNRepository中选择了查看全部。
这导致我进入了具有以下URL的存储库源:
自从我使用Kotlin以来,我就在repositories
的Gradle中向build.gradle.kts
添加了相应的存储库数据。
// Local DynamoDB.
repositories {
maven(url = "https://repository.mulesoft.org/nexus/content/repositories/public")
}
dependencies {
implementation ("com.amazonaws:DynamoDBLocal:1.11.477")
}
对于非本地情况,也可以从以下软件包获得这些进口:
http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-dynamodb/1.11.564/
因此,以下条目也适用:
// Remote DynamoDB.
repositories {
mavenCentral()
}
dependencies {
implementation("com.amazonaws:aws-java-sdk-dynamodb:1.11.564")
}
在为本地或远程版本配置项目后,我能够验证所有包含“文档” 的导入文件都是可用的。
答案 1 :(得分:0)
我假设您已经尝试过这个,但它对我有用,所以我还是要提一下:我确保已经添加了AWS SDK for Java库,然后我刷新了项目。现在一切正常!
我关闭了我的项目并多次重新打开但没有成功,但刷新项目就行了。祝你好运。