简体   繁体   中英

AWS DynamoDB and Android Development (Put Item into table in DynamoDB)

I am having problem regarding getting the items into DynamoDB table. I tried the code i wrote but the Apps crashed and i am lost of what have I Below are may codes for references.

AddItem method

public void AddItem()
    {
        DynamoDB db = new DynamoDB(client);
                Table table = db.getTable(tableName);

        Map<String, AttributeValue> add = new HashMap<String, AttributeValue>();

        // Build the item
        Item item = new Item()
            .withPrimaryKey("id_Tesis", 206)
            .withString("author_Tesis", "20-Bicycle 206")
            .withString("program_Tesis", "206 description")
            .withString("super_Tesis", "Hybrid")
            .withString("title_Tesis", "Brand-Company C")   
            .withInt("title_Tesis", 2004);

        // Write the item to the table 
        table.putItem(item);

    }

MainActivity.java

public void onClick(View v) 
            {
                 dbClient.AddItem();
                 Log.i("sys", "Good");  
            }

LOGCAT ERROR:

06-04 13:26:26.749: E/AndroidRuntime(17001): FATAL EXCEPTION: main
06-04 13:26:26.749: E/AndroidRuntime(17001): Process: com.afdal.ftsmtheses, PID: 17001
06-04 13:26:26.749: E/AndroidRuntime(17001): java.lang.NoClassDefFoundError: com.amazonaws.services.dynamodbv2.document.DynamoDB
06-04 13:26:26.749: E/AndroidRuntime(17001):    at com.afdal.ftsmtheses.Update_Table.AddItem(Update_Table.java:54)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at com.afdal.ftsmtheses.Admin_Page$2.onClick(Admin_Page.java:70)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at android.view.View.performClick(View.java:4478)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at android.view.View$PerformClick.run(View.java:18698)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at android.os.Handler.handleCallback(Handler.java:733)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at android.os.Handler.dispatchMessage(Handler.java:95)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at android.os.Looper.loop(Looper.java:149)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at android.app.ActivityThread.main(ActivityThread.java:5257)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at java.lang.reflect.Method.invokeNative(Native Method)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at java.lang.reflect.Method.invoke(Method.java:515)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
06-04 13:26:26.749: E/AndroidRuntime(17001):    at dalvik.system.NativeStart.main(Native Method)

The reason you see that error is because the library aws-java-sdk-dynamodb isn't exported to the APK. If you use eclipse, please check your project properties -> Java build path -> Order and export.

The DynamoDB document API is offered by AWS Java SDK, but is unavailable in AWS SDK for Android. If you plan to use an SDK on Android, please consider AWS SDK for Android which is fully tested on Android and is optimized for Android in terms of library size, method count number, and performance. See http://aws.amazon.com/mobile/sdk/ for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM