retr122Original post
Rank 2: Process
I'm trying to get Image from my Storage and catch error. How to cast this Object to Image?
Code
Plain text
String currentAvatarFileId = (String) "6468811491b6bba36063Avatar"; Image currentAccountAvatarImage = (Image) storage.getFilePreview( accountsAvatarBucketId, currentAvatarFileId, new Continuation<Object>() { @NotNull @Override public CoroutineContext getContext() { return EmptyCoroutineContext.INSTANCE; }
@Override public void resumeWith(@NotNull Object o) { try { if (o instanceof Result.Failure) { Result.Failure failure =(Result.Failure) o; throw failure.exception; } else { } } catch (Throwable th) { Log.e("ERROR", th.toString()); } } } );Error
java.lang.ClassCastException: kotlin.coroutines.intrinsics.CoroutineSingletons cannot be cast to android.media.Image
Summary
The user is trying to get an Image from storage and is encountering a ClassCastException when trying to assign the result to an Image variable. The solution is to convert the result, which is a byte array, to an Image. The user mentioned that they converted it to a byte array, which resolved the issue.