airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
35.03k stars 5.41k forks source link

Fatal Exception: java.lang.IllegalStateException: Unable to parse composition #2374

Closed Harshjain2094 closed 1 year ago

Harshjain2094 commented 1 year ago

Describe the bug Adding Url to load from Lottie Animation, using function setAnimationUrl(), if it is not able to fetch and load Lottie it throws IllegalStateException.

By adding setFailureListener() it does not get the callback. While if asset is used the callback for failure is triggered.

Steps To Reproduce Steps to reproduce the behavior:

  1. Use this URL https://filebin.net/jo5got9qc9heshtt/sunny_latest.json set as lottieAnimationView.setAnimationUrl("https://filebin.net/jo5got9qc9heshtt/sunny_latest.json")
  2. setFailureListener { it.printStackTrace() }
  3. Run the app it crashes and similar stacktrace will come.
  4. See error

Fatal Exception: java.lang.IllegalStateException: Unable to parse composition at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:78) at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:71) at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:95) at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:88) at com.airbnb.lottie.LottieTask.notifyFailureListeners(LottieTask.java:158) at com.airbnb.lottie.LottieTask.access$200(LottieTask.java:27) at com.airbnb.lottie.LottieTask$1.run(LottieTask.java:133) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7918) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

gpeal commented 1 year ago

I just loaded that animation locally and it worked with out issue. My guess is that something about filebin is not sending down that raw json such that Lottie isn't getting what you expect.

I also noticed that the json file references image_0 and image_1. You'll want those included in a zip file with the json file or you'll want them already available locally but then you need to call setImagesAssetsFolder or setImageAssetDelegate to tell Lottie where to find the images.

Harshjain2094 commented 1 year ago

There is an issue if the network call fails while fetching the Lottie from url, there isn't a way to handle gracefully. Is there a method or callback handle such cases, because currently it crashes the application.

gpeal commented 1 year ago

Yup, you can set your own! https://github.com/airbnb/lottie-android/blob/master/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java#L573

Harshjain2094 commented 1 year ago

I tried with the same approach but if network exception happens it does not come in failure listener. It crashes the app with IllegalStateException

gpeal commented 1 year ago

What exception are you getting that doesn't notify the failure listener?

farooqbitsmedia commented 9 months ago

I am having the same issue with setAnimationUrl(url, cache)

Fatal Exception: java.lang.IllegalStateException: Unable to parse composition
       at com.airbnb.lottie.LottieAnimationView.lambda$static$0(LottieAnimationView.java:72)
       at com.airbnb.lottie.LottieAnimationView$$ExternalSyntheticLambda2.onResult(D8$$SyntheticClass:2)
       at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:84)
       at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:77)
       at com.airbnb.lottie.LottieTask.notifyFailureListeners(LottieTask.java:162)
       at com.airbnb.lottie.LottieTask.lambda$notifyListeners$0$com-airbnb-lottie-LottieTask(LottieTask.java:138)
       at com.airbnb.lottie.LottieTask$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:2)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)