无法找到Behavior类

无法找到Behavior类

Scroll Down

androidx Could not inflate Behavior subclass

在项目升级androidx的过程中,发生Behavior找不到的问题,提示ClassNotFoundException。

经排查,发现需要将类路径完整的填写,才不会报异常。

app:layout_behavior="com.sheepyang1993.bs_onlylive.widget.fabbehavior.ScrollAwareFABBehavior"

原始的报错信息如下:

Process: com.sheepyang1993.onlylive, PID: 23917
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sheepyang1993.onlylive/com.sheepyang1993.bs_onlylive.activity.setting.InitGameDataActivity}: android.view.InflateException: Binary XML file line #37 in com.sheepyang1993.onlylive:layout/bs_onlylive_activity_init_game_data: Could not inflate Behavior subclass com.sheepyang1993.onlylive.widget.fabbehavior.ScrollAwareFABBehavior
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3304)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3443)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:221)
    at android.app.ActivityThread.main(ActivityThread.java:7520)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
 Caused by: android.view.InflateException: Binary XML file line #37 in com.sheepyang1993.onlylive:layout/bs_onlylive_activity_init_game_data: Could not inflate Behavior subclass com.sheepyang1993.onlylive.widget.fabbehavior.ScrollAwareFABBehavior
 Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass com.sheepyang1993.onlylive.widget.fabbehavior.ScrollAwareFABBehavior
    at androidx.coordinatorlayout.widget.CoordinatorLayout.parseBehavior(CoordinatorLayout.java:649)
    at androidx.coordinatorlayout.widget.CoordinatorLayout$LayoutParams.<init>(CoordinatorLayout.java:2896)
    at androidx.coordinatorlayout.widget.CoordinatorLayout.generateLayoutParams(CoordinatorLayout.java:1740)
    at androidx.coordinatorlayout.widget.CoordinatorLayout.generateLayoutParams(CoordinatorLayout.java:112)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1129)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
    at com.sheepyang1993.bs_onlylive.activity.setting.InitGameDataActivity.onCreate(InitGameDataActivity.java:41)
    at android.app.Activity.performCreate(Activity.java:7899)
    at android.app.Activity.performCreate(Activity.java:7886)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3279)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3443)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:221)
    at android.app.ActivityThread.main(ActivityThread.java:7520)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
 Caused by: java.lang.ClassNotFoundException: com.sheepyang1993.onlylive.widget.fabbehavior.ScrollAwareFABBehavior
    at java.lang.Class.classForName(Native Method)
2020-05-28 11:06:04.756 23917-23917/com.sheepyang1993.onlylive E/AndroidRuntime:     at java.lang.Class.forName(Class.java:454)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.parseBehavior(CoordinatorLayout.java:642)
        	... 26 more
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sheepyang1993.onlylive.widget.fabbehavior.ScrollAwareFABBehavior" on path: DexPathList[[zip file "/data/app/com.sheepyang1993.onlylive-seLO_Zfr54TvlmJbyMqelQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.sheepyang1993.onlylive-seLO_Zfr54TvlmJbyMqelQ==/lib/arm64, /data/app/com.sheepyang1993.onlylive-seLO_Zfr54TvlmJbyMqelQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        	... 29 more