gpt4 book ai didi

java - DynamoDB AmazonServiceException : The provided key element does not match the schema

转载 作者:行者123 更新时间:2023-11-30 00:53:34 25 4
gpt4 key购买 nike

所以有人可以指导我为什么我得到这个异常(exception)。
以下是应用程序已停止的异常 bcz 列表:-
11-11 17:54:22.724 5048-5171/com.creation.ceaggregation1 E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: com.creation.ceaggregation1, PID: 5048
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.amazonaws.AmazonServiceException: The provided key element does not match the schema (Service: AmazonDynamoDB; Status Code: 400; Error Code: ValidationException; Request ID: C8BTD5J7Q2477PSOK1F9G3FUTFVV4KQNSO5AEMVJF66Q9ASUAAJG)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:712)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:388)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:199)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:4181)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:1582)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper$SaveObjectHandler.doUpdateItem(DynamoDBMapper.java:1173)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper$2.executeLowLevelRequest(DynamoDBMapper.java:873)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper$SaveObjectHandler.execute(DynamoDBMapper.java:1056)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.save(DynamoDBMapper.java:904)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.save(DynamoDBMapper.java:688)
at com.creation.ceaggregation1.EnterUser$UpdateTable.doInBackground(EnterUser.java:64)
at com.creation.ceaggregation1.EnterUser$UpdateTable.doInBackground(EnterUser.java:40)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:818) 
11-11 17:54:24.769 5048-5171/com.creation.ceaggregation1 I/Process: Sending signal. PID: 5048 SIG: 9

这是我的映射器类:-

@DynamoDBTable(tableName = "agation1")
public class AWSDynamDBMapperClass {
String username;
String password;

@DynamoDBHashKey(attributeName="username")//username
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

@DynamoDBAttribute(attributeName = "password")//password
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}

这是mainActivity代码:-
私有(private)类 UpdateTable 扩展 AsyncTask {
    @Override
protected String doInBackground(String... params) {
String name = params[0];
String password = params[1];

try {
AWSDynamoDBManagerClass manager = new AWSDynamoDBManagerClass();
CognitoCredentialsProvider credentialsProvider = manager.getCredentials(EnterUser.this);
AWSDynamDBMapperClass mapperClass = new AWSDynamDBMapperClass();
mapperClass.setUsername(name);
mapperClass.setPassword(password);

if (credentialsProvider != null && mapperClass != null) {
DynamoDBMapper dynamoDBMapper = manager.initDynamoClient((CognitoCachingCredentialsProvider) credentialsProvider);
dynamoDBMapper.save(mapperClass);//gives error over here

} else {
return "ss";
}
return "rr";

} catch (DynamoDBMappingException ex) {
ex.printStackTrace();
return "exception";
}
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(result.equals("ss")){
Toast.makeText(EnterUser.this, "Entered successfully :) ", Toast.LENGTH_LONG).show();
}else if(result.equals("rr")){
Toast.makeText(EnterUser.this, "Already Existing", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(EnterUser.this, "**Exception Caught**", Toast.LENGTH_SHORT).show();
}
}
}

2 分区键、主键散列键和排序键有什么区别??

3 请建议这里是否需要 AsyncTask。也请提出它的优点和缺点(通过例子,如果可能的话会更好)

感谢您的帮助。

最佳答案

1)这可能是因为表“agation1”没有将分区键设置为“用户名”或者它不是字符串

2)分区键是主键哈希+排序键的组合。两者共同唯一标识一行。但是,您的表不必有排序键。如果没有排序键,则分区键与散列键相同。

3)您必须在不同的线程上进行保存调用,AsyncTask 是一种方法。

关于java - DynamoDB AmazonServiceException : The provided key element does not match the schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40548444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com