我是Android上的新手,需要開發一個操縱EC2和S3(亞馬遜網絡服務)的應用程序。我在VirtualBox上的Ubuntu 10.04上使用Eclipse Indigo。我已經安裝SDK for Android,創建了一個新項目,添加了這些罐子:使用Android操作Amazon EC2的困難
-aws-android-sdk-1.2.2-ec2.jar -aws-android-sdk-1.2.2-s3.jar -aws-Android的SDK-1.2.2-debug.jar
我得到這個錯誤:
Could not find method com.amazonaws.services.ec2.AmazonEC2Client.describeRegions, referenced from method 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());
}
}
}
下面是代碼的AmazonClientMan ager.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;
}
}
謝謝,問候。
我覺得你得到這個例子在這裏亞馬遜演示項目amazons3client()函數是預定義函數u可以使用BasicAWSCredentials類此 –