我正在尝试运行用户登录/注册活动并将用户数据发送到我的DynamoDB 我想要的只是让用户输入他/她的姓名和电子邮件 以下代码来自我的'MainActivity'和我的mapper类('Store.java')
MAINACTIVITY.JAVA
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.amazonaws.auth.CognitoCachingCredentialsProvider;
import com.amazonaws.mobileconnectors.cognito.CognitoSyncManager;
import com.amazonaws.mobileconnectors.cognito.Dataset;
import com.amazonaws.mobileconnectors.cognito.DefaultSyncCallback;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.*;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.*;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText etEmail = (EditText) findViewById(R.id.etEmailInput); //colect e-mail
final EditText etPassword = (EditText) findViewById(R.id.etPasswordInput); //colect password
final Button btnLogin = (Button) findViewById(R.id.btnLogin);
final TextView registerLink = (TextView) findViewById(R.id.tvRegister);
registerLink.setOnClickListener(new View.OnClickListener() { //when 'Sign up today!' gets clicked
@Override
public void onClick(View v) {
Intent registerIntent = new Intent(MainActivity.this, setup1.class); //takes you from MainActivty
MainActivity.this.startActivity(registerIntent); //to setup1Activity
}
});
// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"us-east-2:0f####e#-3e##-####-8##e-de########b0", // Identity Pool ID
Regions.US_EAST_2 // Region
);
//Pass your initialized Amazon Cognito credentials provider to the AmazonDynamoDB constructor:
AmazonDynamoDBClient ddbClient = new AmazonDynamoDBClient(credentialsProvider);
//Pass your initialized DynamoDB client to the DynamoDBMapper constructor:
final DynamoDBMapper mapper = new DynamoDBMapper(ddbClient);
//create Object
//always finish with the below statement
new Thread(new Runnable() {
@Override
public void run() {
final Store userStorage = new Store();
//call methods created in objects
userStorage.setEmail("demo@gmail.com");
userStorage.setName("Adam");
mapper.save(userStorage);
}
}).start();
}
}
STORE.JAVA (Mapper Object)
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.*;
@DynamoDBTable(tableName = "UserStorage")
public class Store {
private String email;
private String name;
@DynamoDBIndexRangeKey(attributeName = "Email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@DynamoDBIndexHashKey(attributeName = "Name")
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
每当我运行我的代码时,mainActivity都无法在手机/模拟器上启动,并且没有数据传输到我的数据库 有人能帮我弄清楚出了什么问题吗?