AWS DynamoDB和Android开发(将项目放入DynamoDB中的表)

时间:2015-06-04 05:32:33

标签: java android eclipse amazon-web-services amazon-dynamodb

我遇到有关将项目放入DynamoDB表的问题。我尝试了我编写的代码,但是应用程序崩溃了,我迷失了以下可能代码以供参考。

AddItem方法

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错误:

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)

1 个答案:

答案 0 :(得分:0)

您看到该错误的原因是因为库aws-java-sdk-dynamodb未导出到APK。如果您使用eclipse,请检查您的项目属性 - &gt; Java构建路径 - &gt;订单和出口。

DynamoDB文档API由AWS Java SDK提供,但在AWS SDK for Android中不可用。如果您打算在Android上使用SDK,请考虑在Android上经过全面测试的适用于Android的AWS SDK,并针对Android在库大小,方法计数和性能方面进行了优化。有关详细信息,请参阅http://aws.amazon.com/mobile/sdk/