我一直在尝试使用AWS SDK将我拍摄的视频上传到一堆S3服务。
这是我从亚马逊示例中获取的用于S3上传的代码。我做的唯一不同的事情是:
使用预定的Uri作为图像所在的文件。
public void uploadToS3(View v) {
AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(
Constants.ACCESS_KEY_ID, Constants.SECRET_KEY));
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(fileUri, filePathColumn,
null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
// Put the image data into S3.
try {
//s3Client.createBucket(Constants.getPictureBucket());
PutObjectRequest por = new PutObjectRequest(
Constants.getPictureBucket(), Constants.PICTURE_NAME,
new java.io.File(filePath)); // Content type is determined
// by file extension.
s3Client.putObject(por);
} catch (Exception exception) {
// displayAlert( "Upload Failure", exception.getMessage() );
}
}
问题是,一旦我尝试创建AmazonS3Client
,应用就会遇到noClassFound
例外。
这是我的Logcat:
05-17 10:42:02.555: E/AndroidRuntime(20310): FATAL EXCEPTION: main
05-17 10:42:02.555: E/AndroidRuntime(20310): java.lang.IllegalStateException: Could not execute method of the activity
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View$1.onClick(View.java:2154)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View.performClick(View.java:2538)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View$PerformClick.run(View.java:9152)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.os.Handler.handleCallback(Handler.java:587)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.os.Handler.dispatchMessage(Handler.java:92)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.os.Looper.loop(Looper.java:123)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invoke(Method.java:507)
05-17 10:42:02.555: E/AndroidRuntime(20310): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
05-17 10:42:02.555: E/AndroidRuntime(20310): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
05-17 10:42:02.555: E/AndroidRuntime(20310): at dalvik.system.NativeStart.main(Native Method)
05-17 10:42:02.555: E/AndroidRuntime(20310): Caused by: java.lang.reflect.InvocationTargetException
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invoke(Method.java:507)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View$1.onClick(View.java:2149)
05-17 10:42:02.555: E/AndroidRuntime(20310): ... 11 more
05-17 10:42:02.555: E/AndroidRuntime(20310): Caused by: java.lang.NoClassDefFoundError: com.amazonaws.services.s3.AmazonS3Client
05-17 10:42:02.555: E/AndroidRuntime(20310): at com.thepoosh.aws.s3upload.android.CameraToAmazonaws3Activity.uploadToS3(CameraToAmazonaws3Activity.java:63)
05-17 10:42:02.555: E/AndroidRuntime(20310): ... 14 more
05-17 10:42:02.555: E/AndroidRuntime(20310): Caused by: java.lang.ClassNotFoundException: com.amazonaws.services.s3.AmazonS3Client in loader dalvik.system.PathClassLoader[/data/app/com.thepoosh.aws.s3upload.android-1.apk]
05-17 10:42:02.555: E/AndroidRuntime(20310): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-17 10:42:02.555: E/AndroidRuntime(20310): ... 15 more
答案 0 :(得分:6)
您的代码提供NoClassDefFoundError
,因为您没有将sdk的库添加到项目中。这是你如何做到的
libs
”(不含"
s)"aws-android-sdk-X.X.X-debug.jar"
libs
。"aws-android-sdk-X.X.X-debug.jar"
希望这有帮助