0

I'm setting up basic app to upload data to DynamoDB. I was following aws tutorial. But I have an error which should not happen. Here's my code:

This is the class for my item to upload:

package com.plexinc.easyorder;

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

@DynamoDBTable(tableName="Bars")
public class Bar {
    private String BarID;
    private String PlaceName;
    private String Address;

    @DynamoDBHashKey(attributeName="BarID")
    public String getBarID(){
        return BarID;
    }

    public void setBarID(String BarID){
        this.BarID = BarID;
    }

    @DynamoDBAttribute(attributeName = "PlaceName")
    public String getPlaceName(){
        return PlaceName;
    }

    public void setPlaceName(String Name) {
        this.PlaceName = Name;
    }

    @DynamoDBAttribute(attributeName = "Address")
    public String getAddress(){
        return Address;
    }

    public void setAddress(String Address) {
        this.Address = Address;
    }
}

And here is the call to dynamoDB:

Bar testBar = new Bar();
testBar.setAddress("thisisAddress 123123");
testBar.setPlaceName("Meltdown");
testBar.setBarID(UUID.randomUUID().toString());

new android.os.AsyncTask<Bar, Void, Void>() {

    @Override
    protected Void doInBackground(Bar... toSave) {
        DynamoDBMapper mapper = new DynamoDBMapper(MainActivity.client);
        mapper.save(toSave);
        return null;
    }
}.execute(testBar);

When I try to executer the code I get the error: class [Lcom.plexinc.easyorder.Bar; must be annotated with interface com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBTable

I checked the syntax on @DynamoDBTable but it is exactly the same as the one in the tutorial. I don't understand and this is certainly a stupid mistake but I can't figure it out.

Thanks for the answers

2
  • The Bar class looks fine. I have tested the Bar class with Java program. It works fine. Please check the AsyncTask. Commented May 28, 2016 at 9:36
  • Thanks for checking the class. I modified my Task to create the DynamoDB client and mapper inside (I only created mapper inside) as I saw other people do on internet. However it does not solve the problem. It is the exact copy of the one in docs.aws.amazon.com/mobile/sdkforandroid/developerguide/… Commented May 28, 2016 at 10:43

1 Answer 1

1

Fixed: You have to create the item (in my case the object Bar) inside the async task (in the doInBackground) and not outside.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.