我正在嘗試創建備份照片應用。
該應用應該將所有圖片上傳到Firebase。當我開始它的應用程序上傳完美的幾張照片,但隨後崩潰與此報告。將*全部*照片上傳到Firebase
java.util.concurrent.RejectedExecutionException:任務[email protected]從[email protected] [拒絕運行,池大小= 2,活動線程= 2 ,排隊任務= 128,完成的任務= 0]
代碼:
StorageReference storage_photos=FirebaseStorage.getInstance().getReference();
private void tryToTakePhotos() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
try {
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};
final String orderBy = MediaStore.Images.Media._ID;
//Stores all the images from the gallery in Cursor
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
int count = cursor.getCount();
int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
Toast.makeText(this, "dd" + count, Toast.LENGTH_SHORT).show();
storage_photos = storage_photos.child(name + "---" + count + "photos");
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
String filePath = cursor.getString(dataColumnIndex);
//Bitmap bitmap = BitmapFactory.decodeFile(filePath);
File file = new File(filePath);
Uri uri = Uri.fromFile(file);
StorageReference riversRef = storage_photos.child(uri.getLastPathSegment());
riversRef.putFile(uri);
}
cursor.close();
Calendar calendar = Calendar.getInstance();
firebase_takePhotos.setValue("taken at: " + calendar.get(Calendar.DAY_OF_MONTH) + "-"
+ (calendar.get(Calendar.MONTH) + 1) + "-"
+ calendar.get(Calendar.YEAR));
}catch (Exception e){
firebase_takePhotos.setValue(""+e);
}
}
}
}
你正在得到這個異常,因爲某些原因有100個排隊交易?你是否以某種方式在循環中創建交易? –