我是 Android 新手,我需要开发一个操作 EC2 和 S3(亚马逊网络服务)的应用程序。我在 VirtualBox 上的 Ubuntu 10.04 上使用 Eclipse Indigo。我已经安装了适用于 Android 的 SDK,创建了一个新项目,添加了这些 jar:
-aws-android-sdk-1.2.2-ec2.jar -aws-android-sdk-1.2.2-s3.jar -aws-android-sdk-1.2.2-debug.jar
我收到了这个错误:
找不到方法 com.amazonaws.services.ec2.AmazonEC2Client.describeRegions,引用自方法 app.workman.Ec2Activity.onCreate。
这是我的活动代码:
public class Ec2Activity extends Activity{
private AmazonClientManager acm;
private AmazonEC2Client ec2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ec2);
acm = new AmazonClientManager();
if (this.acm.hasCredentials()){
ec2 = acm.ec2();
System.out.println(ec2.describeRegions());
}
}
}
这是 AmazonClientManager.java 的代码:
public class AmazonClientManager {
private static final String LOG_TAG = "AmazonClientManager";
private AmazonS3Client s3Client = null;
private AmazonEC2Client ec2Client = null;
public AmazonClientManager() {
}
public AmazonS3Client s3() {
validateCredentials();
return s3Client;
}
public AmazonEC2Client ec2() {
validateCredentials();
return ec2Client;
}
public boolean hasCredentials() {
return PropertyLoader.getInstance().hasCredentials();
}
public void validateCredentials() {
if ( s3Client == null || ec2Client == null) {
Log.i( LOG_TAG, "Creating New Clients." );
// AWSCredentials credentials = new BasicAWSCredentials(PropertyLoader.getInstance().getAccessKey(), PropertyLoader.getInstance().getSecretKey());
AWSCredentials credentials = new PropertiesCredentials(this.getClass().getResourceAsStream("AwsCredentials.properties"));
s3Client = new AmazonS3Client(credentials);
ec2Client = new AmazonEC2Client(credentials);
}
}
public void clearClients() {
s3Client = null;
ec2Client = null;
}
}
感谢和问候。