java.lang.ClassCastException:android.support.design.widget.AppBarLayout无法转换为android.support.design.widget.CoordinatorLayout $ Behavior

时间:2019-05-28 14:40:13

标签: android classcastexception

Caused by: android.view.InflateException: Binary XML file line #27: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout
     Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout
        at android.support.design.widget.CoordinatorLayout.parseBehavior(CoordinatorLayout.java:628)
        at android.support.design.widget.CoordinatorLayout$LayoutParams.<init>(CoordinatorLayout.java:2795)
        at android.support.design.widget.CoordinatorLayout.generateLayoutParams(CoordinatorLayout.java:1703)
        at android.support.design.widget.CoordinatorLayout.generateLayoutParams(CoordinatorLayout.java:112)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:990)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
        at com.sharestar.sns.FilterActivity.onCreate(FilterActivity.java:65)
        at android.app.Activity.performCreate(Activity.java:7028)
        at android.app.Activity.performCreate(Activity.java:7019)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2788)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6687)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
     Caused by: java.lang.ClassCastException: android.support.design.widget.AppBarLayout cannot be cast to android.support.design.widget.CoordinatorLayout$Behavior
        at android.support.design.widget.CoordinatorLayout.parseBehavior(CoordinatorLayout.java:626)
        at android.support.design.widget.CoordinatorLayout$LayoutParams.<init>(CoordinatorLayout.java:2795) 
        at android.support.design.widget.CoordinatorLayout.generateLayoutParams(CoordinatorLayout.java:1703) 
        at android.support.design.widget.CoordinatorLayout.generateLayoutParams(CoordinatorLayout.java:112) 
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:990) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
        at com.sharestar.sns.FilterActivity.onCreate(FilterActivity.java:65) 
        at android.app.Activity.performCreate(Activity.java:7028) 
        at android.app.Activity.performCreate(Activity.java:7019) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2788) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6687) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810) 
Application terminated.

use startactivity to mainactivity
cast error AppbarLayout, CoordinatorLayout
why do this ?

1 个答案:

答案 0 :(得分:0)

您正在尝试将一种对象转换为另一种对象,就像您想告诉系统您有苹果但实际上有梨一样