java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at k.c.b(SourceFile:1)
at q2.c.b(SourceFile:134)
at q2.c.call(SourceFile:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:784)
Oss上传文件,使用kotlin 开发时出现了一个问题
*混淆打包后会报错,正常运行没有问题
报错写法
val put = PutObjectRequest(ConstKey.BUCKET_NAME, ossPath, localFilePath)
put.setProgressCallback { _, currentSize, totalSize ->
val progress: Int = (100 * currentSize / totalSize).toInt()
LogUtils.e("oss", "progress:$progress")
}
修改后
val put = PutObjectRequest(ConstKey.BUCKET_NAME, ossPath, localFilePath)
put.progressCallback =
OSSProgressCallback { request, currentSize, totalSize ->
val progress: Int = (100 * currentSize / totalSize).toInt()
if (progress == 0 || progress == 100) {
LogUtils.e("upload:${request.uploadFilePath} progress:$progress")
}
}
附带阿里oss android 文档路径 简单上传 - 对象存储 OSS - 阿里云
使用的方法异步上传回调
// 构造上传请求。
// 依次填写Bucket名称(例如examplebucket)和Object完整路径(例如exampledir/exampleobject.txt)。
// Object完整路径中不能包含Bucket名称。
PutObjectRequest put = new PutObjectRequest("examplebucket", "exampledir/exampleobject.txt", fileUri);
// 异步上传时可以设置进度回调。
put.setProgressCallback(new OSSProgressCallback() {
@Override
public void onProgress(PutObjectRequest request, long currentSize, long totalSize) {
Log.d("PutObject", "currentSize: " + currentSize + " totalSize: " + totalSize);
}
});
OSSAsyncTask task = oss.asyncPutObject(put, new OSSCompletedCallback() {
@Override
public void onSuccess(PutObjectRequest request, PutObjectResult result) {
Log.d("PutObject", "UploadSuccess");
Log.d("ETag", result.getETag());
Log.d("RequestId", result.getRequestId());
}
@Override
public void onFailure(PutObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
// 请求异常。
if (clientExcepion != null) {
// 客户端异常,例如网络异常等。
clientExcepion.printStackTrace();
}
if (serviceException != null) {
// 服务端异常。
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
// 取消上传任务。
// task.cancel();
// 等待上传任务完成。
// task.waitUntilFinished();
问题出在设置上传回调上,可能是我的写法问题,仅做为开发记录
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)