2015-07-10 46 views
2

林從AWS Android SDK中的指令之後的樣品中, http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/getting-started-store-query-app-data.html 但是當我執行mapper.save()方法,它總是拋出「所提供的密鑰元件不匹配模式」從AWS Android SDK中

07-10 11:47:28.966: E/AndroidRuntime(2030):

com.amazonaws.AmazonServiceException: The provided key element does not

match the schema (Service: AmazonDynamoDBv2; Status Code: 400; 

Error Code: ValidationException; Request ID:

enter image description here

這裏是我的表:

enter image description here

和My Book型號代碼:

package com.example.qingzhong.awssample.dbresources; 


import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBAttribute; 
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBHashKey; 
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBIndexHashKey; 
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBIndexRangeKey; 
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBTable; 

/** 
* Created by qingzhong on 10/7/15. 
*/ 



@DynamoDBTable(tableName = "Books") 
public class Book { 
    private String title; 
    private String author; 
    private int price; 
    private String isbn; 
    private Boolean hardCover; 

    @DynamoDBIndexRangeKey(attributeName = "Title") 
    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    @DynamoDBIndexHashKey(attributeName = "Author") 
    public String getAuthor() { 
     return author; 
    } 

    public void setAuthor(String author) { 
     this.author = author; 
    } 

    @DynamoDBAttribute(attributeName = "Price") 
    public int getPrice() { 
     return price; 
    } 

    public void setPrice(int price) { 
     this.price = price; 
    } 

    @DynamoDBHashKey(attributeName = "ISBN") 
    public String getIsbn() { 
     return isbn; 
    } 

    public void setIsbn(String isbn) { 
     this.isbn = isbn; 
    } 

    @DynamoDBAttribute(attributeName = "Hardcover") 
    public Boolean getHardCover() { 
     return hardCover; 
    } 

    public void setHardCover(Boolean hardCover) { 
     this.hardCover = hardCover; 
    } 
} 

和我的代碼在MainActivity,只需使用mapper.save()方法,沒什麼奇特的:

enter image description here

我不知道哪裏出了問題,因爲所有需要的屬性在Book.class增加,實際上進出口以下從AWS移動SDK

enter image description here

回答

2

最後我工作的指示出來,從鏈接圖片:

http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/getting-started-store-query-app-data.html

實際上是誤導性的,如果你想使用ISBN作爲代碼散列鍵,你需要符合規範ify

1.選擇Hash作爲主鍵類型。 2.對於哈希屬性名稱,請確保已選中字符串並輸入ISBN。點擊繼續。

http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/dynamodb_om.html

+0

我的混亂清抱歉。我同意這是誤導性的,我們會盡快更正文件。感謝您指出了這一點。 – WestonE

+0

你非常歡迎;) – Qing

+0

所以你改變了什麼..? – jerbotron