Android ViewBinding - Caused by:
2024-07-15 本文已影响0人
晖仔Milo
异常信息:
com.ishowedu.aitalk E/qpy-LOGAN-TinkerUncaughtHandler catch exception:android.view.InflateException: Binary XML file line #610 in com.ishowedu.aitalk:layout/vh_textbook_dub_srt: Binary XML file line #610 in com.ishowedu.aitalk:layout/vh_textbook_dub_srt: Error inflating class com.ishowedu.aitalk.widget.TouchRecordView
com.ishowedu.aitalk E/qpy-LOGAN-Caused by: android.view.InflateException: Binary XML file line #610 in com.ishowedu.aitalk:layout/vh_textbook_dub_srt: Error inflating class com.ishowedu.aitalk.widget.TouchRecordView
com.ishowedu.aitalk E/qpy-LOGAN-Caused by: java.lang.reflect.InvocationTargetException
com.ishowedu.aitalk E/qpy-LOGAN- at java.lang.reflect.Constructor.newInstance0(Native Method)
com.ishowedu.aitalk E/qpy-LOGAN-Caused by: java.lang.ClassCastException: com.ishowedu.aitalk.widget.TouchRecordView cannot be cast to android.widget.ImageView
com.ishowedu.aitalk E/qpy-LOGAN- at com.ishowedu.aitalk.databinding.RecordViewTouchBinding.bind(RecordViewTouchBinding.java:87)
com.ishowedu.aitalk E/qpy-LOGAN- at com.ishowedu.aitalk.widget.TouchRecordView.init(TouchRecordView.java:84)
com.ishowedu.aitalk E/qpy-LOGAN- at com.ishowedu.aitalk.widget.TouchRecordView.<init>(TouchRecordView.java:55)
com.ishowedu.aitalk E/qpy-LOGAN- ... 76 more
原因,封装好的view-id与内部view-id重复导致。
解决方法如下
<com.ishowedu.aitalk.widget.TouchRecordView
android:id="@+id/imgRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/waveView"
tools:viewBindingIgnore="true" />
image.png