java.lang.RuntimeException:Unable to start activity ComponentInfo{com.xx.yy/com.xx.yy.ui.main.MainActivity}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class com.airbnb.lottie.LottieAnimationView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/arg. Make sure other views do not use the same id.
2 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2391)
3 ......
4 Caused by:
5 java.lang.IllegalArgumentException:Wrong state class, expecting View State but received class com.airbnb.lottie.LottieAnimationView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/arg. Make sure other views do not use the same id.
6 android.view.View.onRestoreInstanceState(View.java:13038)
7 android.view.View.dispatchRestoreInstanceState(View.java:13014)
8 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2798)
9 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2798)
10 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2798)
11 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2798)
12 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2798)
13 android.view.View.restoreHierarchyState(View.java:12992)
14 android.support.v4.app.Fragment.restoreViewState(SourceFile:415)
15 android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1454)
16 android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(SourceFile:1759)
17 android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1827)
18 android.support.v4.app.FragmentManagerImpl.dispatchStateChange(SourceFile:3244)
19 android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:3200)
20 android.support.v4.app.FragmentController.dispatchActivityCreated(SourceFile:195)
21 android.support.v4.app.FragmentActivity.onStart(SourceFile:597)
22 android.support.v7.app.AppCompatActivity.onStart(SourceFile:177)
23 android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174)
24 android.app.Activity.performStart(Activity.java:5373)
25 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2344)
26 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
27 android.app.ActivityThread.access$800(ActivityThread.java:166)
28 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
29 android.os.Handler.dispatchMessage(Handler.java:110)
30 android.os.Looper.loop(Looper.java:193)
31 android.app.ActivityThread.main(ActivityThread.java:5387)
32 java.lang.reflect.Method.invokeNative(Native Method)
33 java.lang.reflect.Method.invoke(Method.java:515)
34 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:831)
35 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:647)
36 dalvik.system.NativeStart.main(Native Method)
通过 git diff tag1 tag2
, 我发现了一处疑点
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/icon"
android:layout_width="22dp"
android:layout_height="22dp"
app:lottie_autoPlay="true"
app:lottie_fileName="ani_top_sheet_tip.json"
app:lottie_loop="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
原因是这个 LottieAnimationView的名字命名太不走心,和同Activity中的id重复, 尤其是icon这种大众id,这时候需要把Lottie的id设置成独一无二的
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_specialName"
android:layout_width="22dp"
android:layout_height="22dp"
app:lottie_autoPlay="true"
app:lottie_fileName="ani_top_sheet_tip.json"
app:lottie_loop="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
建议所有lottie动画id命名前缀区分下
网友评论