无法对 lapism/SearchView 中的空对象调用 void android.view.View.setElevation(float)

Can't call void android.view.View.setElevation(float) on null object in lapism/SearchView

我在我的项目中使用库 lapism/SearchView (https://github.com/lapism/SearchView) 但我只在 Android 5.0:

上遇到运行时异常
A/art: art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: can't call void android.view.View.setElevation(float) on null object
A/art: art/runtime/check_jni.cc:65]     in call to CallVoidMethodV
A/art: art/runtime/check_jni.cc:65]     from void android.animation.PropertyValuesHolder.nCallFloatMethod(java.lang.Object, long, float)
A/art: art/runtime/check_jni.cc:65] "main" prio=5 tid=1 Runnable
A/art: art/runtime/check_jni.cc:65]   | group="main" sCount=0 dsCount=0 obj=0x757838b0 self=0xb8994958
A/art: art/runtime/check_jni.cc:65]   | sysTid=28467 nice=0 cgrp=apps sched=0/0 handle=0xb6f80058
A/art: art/runtime/check_jni.cc:65]   | state=R schedstat=( 0 0 0 ) utm=27 stm=10 core=1 HZ=100
A/art: art/runtime/check_jni.cc:65]   | stack=0xbe01e000-0xbe020000 stackSize=8MB
A/art: art/runtime/check_jni.cc:65]   | held mutexes= "mutator lock"(shared held)
A/art: art/runtime/check_jni.cc:65]   native: #00 pc 00004828  /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
A/art: art/runtime/check_jni.cc:65]   native: #01 pc 00002ec5  /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
A/art: art/runtime/check_jni.cc:65]   native: #02 pc 0024437d  /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+68)
A/art: art/runtime/check_jni.cc:65]   native: #03 pc 0022774b  /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+394)
A/art: art/runtime/check_jni.cc:65]   native: #04 pc 000af2db  /system/lib/libart.so (art::JniAbort(char const*, char const*)+582)
A/art: art/runtime/check_jni.cc:65]   native: #05 pc 000afa21  /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60)
A/art: art/runtime/check_jni.cc:65]   native: #06 pc 000b0613  /system/lib/libart.so (art::ScopedCheck::CheckVirtualMethod(_jobject*, _jmethodID*)+402)
A/art: art/runtime/check_jni.cc:65]   native: #07 pc 000ba087  /system/lib/libart.so (art::CheckJNI::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list)+70)
A/art: art/runtime/check_jni.cc:65]   native: #08 pc 0006028f  /system/lib/libandroid_runtime.so (???)
A/art: art/runtime/check_jni.cc:65]   native: #09 pc 000721e5  /data/dalvik-cache/arm/system@framework@boot.oat (Java_android_animation_PropertyValuesHolder_nCallFloatMethod__Ljava_lang_Object_2JF+132)
A/art: art/runtime/check_jni.cc:65]   at android.animation.PropertyValuesHolder.nCallFloatMethod(Native method)
A/art: art/runtime/check_jni.cc:65]   at android.animation.PropertyValuesHolder.access0(PropertyValuesHolder.java:38)
A/art: art/runtime/check_jni.cc:65]   at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1296)
A/art: art/runtime/check_jni.cc:65]   at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:952)
A/art: art/runtime/check_jni.cc:65]   at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1207)
A/art: art/runtime/check_jni.cc:65]   at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1248)
A/art: art/runtime/check_jni.cc:65]   at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:659)
A/art: art/runtime/check_jni.cc:65]   at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:682)
A/art: art/runtime/check_jni.cc:65]   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:792)
A/art: art/runtime/check_jni.cc:65]   at android.view.Choreographer.doCallbacks(Choreographer.java:596)
A/art: art/runtime/check_jni.cc:65]   at android.view.Choreographer.doFrame(Choreographer.java:556)
A/art: art/runtime/check_jni.cc:65]   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:778)
A/art: art/runtime/check_jni.cc:65]   at android.os.Handler.handleCallback(Handler.java:739)
A/art: art/runtime/check_jni.cc:65]   at android.os.Handler.dispatchMessage(Handler.java:95)
A/art: art/runtime/check_jni.cc:65]   at android.os.Looper.loop(Looper.java:155)
A/art: art/runtime/check_jni.cc:65]   at android.app.ActivityThread.main(ActivityThread.java:5696)
A/art: art/runtime/check_jni.cc:65]   at java.lang.reflect.Method.invoke!(Native method)
A/art: art/runtime/check_jni.cc:65]   at java.lang.reflect.Method.invoke(Method.java:372)
A/art: art/runtime/check_jni.cc:65]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
A/art: art/runtime/check_jni.cc:65]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

任何人都知道如何解决这个问题吗?

要解决此问题,您必须更新包含 SearchViewAppBarLayout 的 XML 文件。将 android:stateListAnimator="@null" 添加到您的 AppBarLayout 中,如下所示。

 <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stateListAnimator="@null">

它显​​示 android:stateListAnimator="@null" 属性 stateListAnimator 仅在 API 级别 21 中使用的警告。但是我已经检查了库的源代码并且它当它试图设置 mAppBarLayout.setStateListAnimator(null);

时在 SearchBehavior class 中崩溃

编辑

正如下面评论中提到的,这个问题更多地与 android 组件相关 native crash on scrolling in RecyclerView+CollapsingToolbarLayout

AppBarLayout 的属性app:elevation="..dp" 有助于解决这个问题